我的Android应用程序依赖于多个Android库(例如A,B,C,D)。我想生成不同的apk,其中apk1仅需要消耗A,B,而apk2需要消耗B,C。
我通过做这样的事情探索了Android产品风味概念的选项,
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,但是它包括每种口味的所有库。如何避免这种情况?
对您的使用风味特定的指令dependencies
。implementation
例如,您可以使用demoImplementation
和来代替fullImplementation
。在demo
建立将包括demoImplementation
相关性,同时full
建立将包括fullImplementation
依赖性。
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'
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句