android - 在根项目 ''中找不到路径为 ''的项目

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

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

文件夹结构很简单

rootFolder    
1) carEgiriLibrary    
2) carEgiriPuneBangalore

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

Error:(5, 0) Project with path ':personal:mCruiseOn:carEgiriLibrary' could not be found in root project 'carEgiriPuneBangalore'. Open File


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

最佳答案

首先,在您的根项目中,您应该具有以下结构:

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'

  //...

关于android - 在根项目 ''中找不到路径为 ''的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35424583/

相关文章:

java - JSONArrayRequest 和 PHP 对不起作用

java - 重叠数据标签 (MPAndroidChart)

Android Studio报错 ➡ Cannot run program "git"... CreateProcess error=2, 系统找不到指定的文件

java - Android Studio 3.o 不提供 android

android - 构建gradle模块android studio中的错误

java - Android FileObserver onEvent 没有被调用

java - 按返回按钮完成一系列 Activity

android - EditText 填充在 Android 中无法正常工作

android - 无法使用对话框流完成构建 gradle

android - Gradle 错误 - 无法在任务 ':project:mergeDebugResources' 上调用 IncrementalTask​​.taskAction()