11

允许这种结构吗?

MyProject/
 | settings.gradle
 + app/
    | build.gradle
 + libraries/
    + lib1/
       | settings.gradle
       | build.gradle
       + libraries/
          + sublib1/
             | build.gradle
          + sublib2/
             | build.gradle
    + lib2/
       | build.gradle

我曾与 Ant 一起工作,但使用 Gradle 我的项目找不到 sublib1 或 sublib2。

当我运行 gradle 我得到这个错误:

* What went wrong:
A problem occurred evaluating project ':libraries:lib1'.
> Project with path ':libraries:sublib1' could not be found in project ':libraries:lib1'.

这是来自MyProject的settings.gradle

include ':libraries:lib1'
include ':libraries:lib2'

这是来自MyProject的build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':libraries:lib1')
    compile project(':libraries:lib2')
}

android {
    compileSdkVersion 15
    buildToolsVersion "17.0.0"

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

        instrumentTest.setRoot('tests')
    }
}

这是来自lib1的settings.gradle

include ':libraries:sublib1'
include ':libraries:sublib2'

这是来自lib1的build.gradle

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
        compile project(':libraries:sublib1')
        compile project(':libraries:sublib2')
    }
}

apply plugin: 'android-library'

android {
    compileSdkVersion 15
}
4

2 回答 2

3

Gradle 似乎不支持多个settings.gradle文件。此文件应仅存在于项目根目录中,并且应包含所有子项目:

include ':libraries:lib1', ':libraries:lib1:libraries:sublib1', ':libraries:lib1:libraries:sublib2', ':libraries:lib2'

来源:http ://www.gradle.org/docs/current/userguide/multi_project_builds.html

于 2013-06-03T15:09:54.063 回答
0

您可以将其他库作为库项目中的依赖项。在您的 settings.gradle 中只包含所有应用程序/库模块。

在依赖于另一个库模块的库项目中,您只需将其添加为依赖项,就像项目中的任何其他模块一样。

在我的一个库模块中,gradle 中的依赖项如下所示:

dependencies {
    compile project(':library1')
    compile project(':library2')
    compile project(':library3')
}
于 2013-08-09T12:40:42.643 回答