【问题标题】:Project with path ':mypath' could not be found in root project 'myproject'在根项目“myproject”中找不到路径为“:mypath”的项目
【发布时间】:2014-07-01 15:31:49
【问题描述】:

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

项目结构:

完整结构(编辑 2):

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')
    }
}

【问题讨论】:

  • 你没有settings.gradle文件吗?
  • @Salem 不,我没有
  • 问题不清楚,请附上完整的项目结构,这个 gradle 文件在哪里以及项目目录结构是什么样的,因为你给的东西根本不像一个 gradle 项目。
  • @pyus13 问题已编辑
  • 除了 build.gradle 之外,没有什么像 gradle 项目。从 AS 的 botton panel 打开 Message Window 并确保它没有显示像 "Not a Gradle Project" 这样的警告消息。

标签: android eclipse android-studio


【解决方案1】:

如果Igor's 的回答不起作用,那么您很可能在引用项目名称之前缺少冒号(:)

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

确保包含带有 : 作为前缀的项目

include ':progressfragment'

【讨论】:

    【解决方案2】:

    删除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 时,通常会发生此问题。如果您在 react-native >0.60 中创建一个新项目,您将看到与上述相同的设置

    【讨论】:

      【解决方案3】:

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

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

      在 Gradle Scripts 下的build.gradle(依赖)中

      【讨论】:

        【解决方案4】:

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

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

        include ':progressfragment'
        

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

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

        【讨论】:

        • 模块在 settings.gradle 中不存在。我检查并包括在内。它对我有用。
        • 为我工作!虽然我仍然觉得 Gradle 以这种方式工作很奇怪。就像我不想在我的构建文件中声明一个“项目(”项目名称“){//settings ...}”一样,如果我不想包含它?为什么我必须有一个单独的文件,其中唯一包含的是我在实际构建文件中定义的所有项目的列表。我在构建文件中定义的所有那些项目?是的,我实际上希望它们在我的构建中!我很好奇是否有人知道 settings.gradle 背后的设计原因?
        • 在某些情况下,您希望将模块作为项目的一部分包含在内,但不将其用作依赖项。例如,在我正在开发的项目中,我们有 2 个 android 应用程序,一个是 UI 部分,另一个是内容提供程序应用程序。我们不想在构建期间依赖于内容提供程序应用程序,但希望能够在同一个项目中轻松更改和查看它的代码。
        • 不为我工作而颤抖。
        猜你喜欢
        • 2013-05-21
        • 2016-05-27
        • 1970-01-01
        • 2018-12-04
        • 2023-04-08
        • 1970-01-01
        • 1970-01-01
        • 2019-03-10
        • 1970-01-01
        相关资源
        最近更新 更多