事情有点复杂。我已经在 gradle experimental 0.8.0 上测试过
在你需要的图书馆:
model{
android {
...
publishNonDefault true
productFlavors {
create("flavor1") {
}
create("flavor2") {
}
}
}
}
在您需要的应用程序上:
model {
android {
...
publishNonDefault true
productFlavors {
create("flavor1") {
}
create("flavor2") {
}
}
}
}
//after the model is closed !!
configurations {
flavor1DebugCompile
flavor1ReleaseCompile
flavor2DebugCompile
flavor2ReleaseCompile
}
dependencies {
...
flavor1DebugCompile project(path: ':mylibrary', configuration: 'flavor1Debug')
flavor1ReleaseCompile project(path: ':mylibrary', configuration: 'flavor1Release')
flavor2DebugCompile project(path: ':mylibrary', configuration: 'flavor2Debug')
flavor2ReleaseCompile project(path: ':mylibrary', configuration: 'flavor2Release')
}
希望,如果您运行完整的汇编,您将获得 2 个 apk,每种口味一个。我从 cmd 中使用了“./gradlew build”并得到了它们。请注意,对于您的库,您还将获得每种口味的 AAR