这对于大多数人来说都是很正常的http://www.gradle.org/docs/current/userguide/multi_project_builds.html http://www.gradle.org/docs/current/userguide/multi_project_builds.html页。但是你需要添加
evaluationDependsOn(':project1')
evaluationDependsOn(':project2')
这样 gradle 就会在 module 之前评估project1和project2。在所有包含代码的项目中,您将需要有一个空的 build.gradle 文件。如果需要,这还允许您自定义项目。
Example: https://github.com/ethankhall/AndroidComplexBuild https://github.com/ethankhall/AndroidComplexBuild
在项目的根目录中添加 build.gradle。所以你需要 4 个包含有用信息的东西。
/build.gradle
/settings.gradle
/project1/build.gradle
/project2/build.gradle
/module/build.gradle
在 /build.gradle 中放入
dependencies {
project(":module")
}
在 /settings.gradle 中放置
include ':module'
include ':project1', ':project1:A1', ':project1:B1', ':project1:Z1'
include ':project2', ':project2:A2', ':project2:B2', ':project2:Z2'
在 /project1/build.gradle 中放入
apply plugin: 'java'
subprojects {
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
repositories{
mavenCentral()
}
//Anything else you would need here that would be shared across all subprojects
}
/project2/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
subprojects {
apply plugin: 'android-library'
android {
compileSdkVersion 17
buildToolsVersion "17.0"
}
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
repositories{
mavenCentral()
}
//Anything else you would need here that would be shared across all subprojects
}
在 /module/build.gradle 中放入
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
evaluationDependsOn(':project1')
evaluationDependsOn(':project2')
apply plugin: 'android'
android {
compileSdkVersion 17
buildToolsVersion "17.0"
}
dependencies {
compile project(":project1:A1")
compile project(":project1:B1")
compile project(":project1:Z1")
compile project(":project2:A2")
compile project(":project2:B2")
compile project(":project2:Z2")
}