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

问题描述 投票:0回答:6

我从 Eclipse 迁移到 android studio 0.5.8,将我的项目导入到 android studio 后,我收到错误

Project with path ':progressfragment' could not be found in root project 'project_name'.

项目结构:

enter image description here

完整结构(编辑2):

enter image description here

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')
    }
}
android eclipse android-studio
6个回答
264
投票

仅拥有

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

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

include ':progressfragment'

到该文件。然后同步 Gradle 就可以了。

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


5
投票

删除 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'

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


5
投票

如果 Igor 的答案不起作用,很可能您在引用项目名称之前错过了 冒号(:)

省略它会产生完全相同的错误。

确保您包含以

:
作为前缀的项目

include ':progressfragment'

3
投票

您必须在 'settings.gradle' 文件中包含该依赖项名称和版本..

include ':paytabs_sdk-v4.0.1'
include ':dtapl-3.5.3'

0
投票

检查模块的 build.gradle.kts - 模块名称前是否包含冒号 (:) -

语法 - 实现(项目(“:模块文件夹名称”))

真实例子- 实现(项目(“:功能”)) - 其中功能是您的模块文件夹名称


-5
投票

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

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

在 Gradle 脚本下的

build.gradle
(依赖项)中

© www.soinside.com 2019 - 2024. All rights reserved.