我的android应用依赖于多个android库(例如A,B,C,D)。我想从中生成不同的apk,例如apk1只需要消耗A,B,而apk2需要只消耗B,C。
我通过做类似的事情探索了Android product flavor概念的选择,
android {
...
defaultConfig {...}
buildTypes {
debug{...}
release{...}
}
// Specifies one flavor dimension.
flavorDimensions "version"
productFlavors {
demo {
// Assigns this product flavor to the "version" flavor dimension.
// If you are using only one dimension, this property is optional,
// and the plugin automatically assigns all the module's flavors to
// that dimension.
dimension "version"
applicationIdSuffix ".demo"
versionNameSuffix "-demo"
}
full {
dimension "version"
applicationIdSuffix ".full"
versionNameSuffix "-full"
}
}
}
现在,它正在生成具有多种产品的APK,但它包括每种口味的所有库。如何避免这种情况?
答案 0 :(得分:1)
为dependencies
使用特定于风味的指令。例如,您可以使用implementation
和demoImplementation
代替fullImplementation
。 demo
构建将包括demoImplementation
依赖性,而full
构建将包括fullImplementation
依赖性。
documentation page that you linked to显示了一个使用free
风格的示例:
dependencies {
// Adds the local "mylibrary" module as a dependency to the "free" flavor.
freeImplementation project(":mylibrary")
// Adds a remote binary dependency only for local tests.
testImplementation 'junit:junit:4.12'
// Adds a remote binary dependency only for the instrumented test APK.
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}