【问题标题】:Project with path '' could not be found in root project ''在根项目“”中找不到路径为“”的项目
【发布时间】:2016-05-27 06:16:21
【问题描述】:

我刚刚从 Eclipse 导入了一个项目。该项目包含一个链接到主 apk 项目的 android 库项目。

文件夹结构很简单我有

rootFolder    
1) carEgiriLibrary    
2) carEgiriPuneBangalore

我在 Gradle 尝试同步时收到此错误。

错误:(5, 0) 在根项目“carEgiriPuneBangalore”中找不到路径为“:personal:mCruiseOn:carEgiriLibrary”的项目。 打开文件

Gradle-wrapper.properties

   #Wed Apr 10 15:27:10 PDT 2013
   distributionBase=GRADLE_USER_HOME
   distributionPath=wrapper/dists
   zip
   StoreBase=GRADLE_USER_HOME
   zipStorePath=wrapper/dists
   distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip

gradle.build

apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':personal:mCruiseOn:carEgiriLibrary')
    compile 'com.google.android.gms:play-services:8.4.0'
    //compile project(':adt-bundle-linux-x86-20140702:sdk:extras:google:google_play_services:libproject:google-play-services_lib')
 }

编辑,整个 build.gradle

apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':personal:mCruiseOn:carEgiriLibrary')
    compile 'com.google.android.gms:play-services:8.4.0'
    //compile project(':adt-bundle-linux-x86-20140702:sdk:extras:google:google_play_services:libproject:google-play-services_lib')
}

android {
    compileSdkVersion 10
    buildToolsVersion "21.1.2"

    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')
    }
}
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

【问题讨论】:

  • 你想在这里做什么? include ':personal:mCruiseOn:carEgiriLibrary' ? inclde &lt;project&gt; 行通常进入 settings.gradle,而不是 build.gradle
  • 我是工作室的新手,在 SO (stackoverflow.com/questions/23640059/…) 建议我加入这一行..我会删除它
  • 现在我得到一个不同的错误 'Error:(5, 0) Project with path ':personal:mCruiseOn:carEgiriLibrary' can not be found in root project 'carEgiriPuneBangalore'。 打开文件'
  • 你有 settings.gradle 文件吗?如果您仔细阅读了您链接的问题中的答案,则该行需要进入 settings.gradle,而不是 build.gradle
  • 我没有 settings.gradle 文件

标签: android android-studio gradle android-gradle-plugin


【解决方案1】:

在您的项目中缺少 settings.gradle, 创建一个具有该名称的文件或从另一个项目复制并写入您的模块:

include 'desktop', 'android', 'core', 'etc...'

【讨论】:

    【解决方案2】:

    在 Android Studio 中打开 Project 视图,你会发现 settings.gradle 打开它并将你的库添加到 include 中

    例如 包括 ':app', ':Android-SDK-master', ':library', ':zxing-android', ':your library'

    【讨论】:

      【解决方案3】:

      首先,在您的根项目中,您应该有这样的结构:

      rootFolder    
      |----carEgiriLibrary    
      |------build.gradle
      |----carEgiriPuneBangalore
      |------build.gradle
      |--settings.gradle
      |--build.gradle
      

      settings.gradle:

      include ':carEgiriLibrary' , ':carEgiriPuneBangalore'
      

      然后在carEgiriPuneBangalore/build.gradle 你必须更改你的文件。

      apply plugin: 'com.android.application'
      
      dependencies {
              compile fileTree(dir: 'libs', include: '*.jar')
              compile project(':carEgiriLibrary')   //You have to use the same name used in settings.gradle
              compile 'com.google.android.gms:play-services:8.4.0'
      }
      
      android {
          compileSdkVersion 23  //you need 23 since you are using the  gsm:8.4.0
      
         ...
      }
      

      最后你必须在 carEgiriLibrary 文件夹中放一个build.gradle

       apply plugin: 'com.android.library'
      
        //...
      

      【讨论】:

      • 我现在有这个错误.. \Gradle 'carEgiriPuneBangalore' 项目刷新失败错误:未找到名称为 'default' 的配置。
      • @Siddharth 也许你应该学习一点 gradle 语法。这些是 android 的标准插件。
      【解决方案4】:

      从您的 build.gradle 中替换以下行

      compile project(':adt-bundle-linux-x86-20140702:sdk:extras:google:google_play_services:libproject:google-play-services_lib')
      

      有了这个

      compile 'com.google.android.gms:play-services:8.4.0'
      

      如果您遇到问题,请告诉我

      【讨论】:

      • 同样的问题@第 3 行在这个 chnage 之后也
      • 你可以发布你的整个 gradle 文件(app.gradle 和 projet.gradle)
      • 我没有这两个文件。我刚刚从 Eclipse 迁移,从未在工作室中运行过这个项目。我将粘贴 build.gradle
      • 将此“compileSdkVersion 10”更改为 23 而不是 10。
      • 删除这个“include ':personal:mCruiseOn:carEgiriLibrary'”,因为你已经添加了它的依赖关系。
      猜你喜欢
      • 2014-07-01
      • 2018-12-04
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 2019-03-10
      • 1970-01-01
      • 2016-06-07
      • 1970-01-01
      相关资源
      最近更新 更多