Build Variant
An android gradle plugin that allows to compose the final package in multiple dimensions.
BuildVariant = ProductFlavor x BuildType
two dimensions
The most common is this:
productFlavors {
pro {
}
fre {
}
}
lintOptions {
abortOnError false
}
buildTypes {
debug {
}
release {
}
}
Among them, buildTypes generally have debug or release, indicating the type of compilation, and usually make some distinctions in obfuscated code, adjustable, and resource compression.
productFlavor is to meet the requirement of "the same project, according to a small distinction, to make different packages".
The combination of these two dimensions produces the following packets:
- proDebug
- proRelease
- freDebug
- proRelease
more dimensions
flavorDimensions 'abi', 'version'
productFlavors {
pro {
dimension 'version'
}
fre {
dimension 'version'
}
arm {
dimension 'abi'
}
mips {
dimension 'abi'
}
}
buildTypes {
debug {
}
release {
}
}
productFlavor itself defines 2 dimensions, record buildType, there are three dimensions, and the following packages will be generated:
- armProDebug
- armProRelease
- armFreDebug
- armFreRelease
- mipsProDebug
- mipsProRelease
- mipsFreDebug
- mipsFreRelease
For each dimension combination, you can set its own dependency and test source. Let's do an example.
Flavor 与 Dependency
need
There are several flavors in the module, such as: fre and pro, which depend on different libraries, some of which are local jar libraries and some are remote libraries.
plan
Traverse Build Variant
need
The android sdk of Bugtags has a function of automatically uploading the symbol table. Initially, it was configured like this:
apply plugin: 'com.bugtags.library.plugin'
bugtags {
appKey "APP_KEY"
appSecret "APP_SECRET"
mappingUploadEnabled false
}
Later, we added a beta-live mechanism to distinguish between testing and online APPs. In this way, there are two sets of APP_KEY and APP_SECRET for the same APP. Obviously, the above configuration method is not applicable.
plan
The android gradle plugin provides the android.applicationVariants index to traverse all build variants
. Later, we adopted a plan to traverse the Build Variants and set the extension information to be compatible with this requirement.
afterEvaluate {
android.applicationVariants.each { variant ->
def bugtagsAppKey = null;
def bugtagsAppSecret = null;
if (variant.name.contains("debug")) {
bugtagsAppKey = 'APP_KEY_BETA'
bugtagsAppSecret = 'APP_SECRET_BETA'
} else if (variant.name.contains("release")) {
bugtagsAppKey = 'APP_KEY_LIVE'
bugtagsAppSecret = 'APP_SECRET_LIVE'
}
variant.ext.bugtagsAppKey = bugtagsAppKey
variant.ext.bugtagsAppSecret = bugtagsAppSecret
}
}
apply plugin: 'com.bugtags.library.plugin'
Summarize
This article mainly introduces the concept of build variant, and also introduces two daily application cases. I hope everyone has to help.
References
something wrong? Leave a message under the article or add a QQ group: 453503476, I hope it can help you.
To receive the latest blog posts in a timely manner, please follow:
"mobdev" WeChat public account QR code