Android 在根项目“myproject”中找不到路径为“:mypath”的项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23640059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:20:13  来源:igfitidea点击:

Project with path ':mypath' could not be found in root project 'myproject'

androideclipseandroid-studio

提问by Chulo

I'm migrated from Eclipse to android studio 0.5.8, after importing my project to android studio i was getting the error Project with path ':progressfragment' could not be found in root project 'project_name'.

我从 Eclipse 迁移到 android studio 0.5.8,在将我的项目导入到 android studio 后我收到错误Project with path ':progressfragment' could not be found in root project 'project_name'.

Project Struture :

项目结构:

Libs

enter image description here

在此处输入图片说明

Complete Structure (edit 2) :

完整结构(编辑 2):

enter image description here

在此处输入图片说明

Gradle.build:

Gradle.build:

apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':progressfragment')
    compile project(':viewpagerindicatorlibrary')
    compile project(':ZBarScannerActivity')
    compile project(':google-play-services_lib')
    compile project(':SwitchCompatLibrary')
    compile project(':actionbarsherlock')
    compile project(':librarymultichoice')
}



buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

android {
    compileSdkVersion 14
    buildToolsVersion "19.0.1"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

回答by Igor ?orda?

It's not enough to have just compile project("xy")dependency. You need to configure root project to include all modules (or to call them subprojects but that might not be correct word here).

仅仅有compile project("xy")依赖是不够的。您需要配置根项目以包含所有模块(或将它们称为子项目,但这里可能不是正确的词)。

Create a settings.gradlefile in the root of your project and add this:

在项目的根目录中创建一个settings.gradle文件并添加以下内容:

include ':progressfragment'

to that file. Then sync Gradle and it should work.

到那个文件。然后同步 Gradle,它应该可以工作。

Also one interesting side note: If you add ':unexistingProject' in settings.gradle(project that you haven't created yet), Gradle will create folder for this project after sync (at least in Android studio this is how it behaves). So, to avoid errors with settings.gradlewhen you create project from existing files, first add that line to file, sync and then put existing code in created folder. Unwanted behavior arising from this might be that if you delete the project folder and then sync folder will come back empty because Gradle sync recreated it since it is still listed in settings.gradle.

还有一个有趣的旁注:如果您在settings.gradle(您尚未创建的项目)中添加 ':unexistingProject' ,Gradle 将在同步后为此项目创建文件夹(至少在 Android Studio 中这是它的行为方式)。因此,当您从现有文件创建项目时,为避免settings.gradle出现错误,请先将该行添加到文件中,同步然后将现有代码放入创建的文件夹中。由此产生的不良行为可能是,如果您删除项目文件夹,然后同步文件夹将返回空,因为 Gradle sync 重新创建了它,因为它仍然列在settings.gradle 中

回答by Joe 89

Remove all the texts in android/settings.gradle and paste the below code

删除 android/settings.gradle 中的所有文本并粘贴以下代码

rootProject.name = '****Your Project Name****'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'

This issue will usually happen when you migrate from react-native < 0.60 to react-native >0.60. If you create a new project in react-native >0.60 you will see the same settings as above mentioned

当您从 react-native < 0.60 迁移到 react-native >0.60 时,通常会发生此问题。如果您在 react-native >0.60 中创建一个新项目,您将看到与上述相同的设置

回答by CFA

I got similar error after deleting a subproject, removed

删除子项目后出现类似错误,已删除

"*compile project(path: ':MySubProject', configuration: 'android-endpoints')*"

in build.gradle(dependencies) under Gradle Scripts

build.gradleGradle Scripts 下的(依赖项)