背景
在开发过程中,尤其是涉及到2B的产品,我们往往是在一个工程中做多个软件的定制开发,其中比较简单和常见的就是应用名称和应用logo的动态变更,这些变更跟app绑定,当App编译完成后就不再修改,这样的场景往往就是在打包编译是动态配置即可。
方法
这些需求其实Gradle已经为我们考虑到了,并且提供了一些可行的方案来支持。
方式一 :使用manifestPlaceholders
build.gradle脚本配置manifestPlaceholders
android {
... ...
defaultConfig {
... ...
manifestPlaceholders = [my_app_ame: "demo1", my_app_icon: "@mipmap/logo1"]
}
// 依据debug/release变动的话设置如下
buildTypes {
debug {
manifestPlaceholders = [my_app_ame: "demo1", my_app_icon: "@mipmap/logo1"]
}
}
flavorDimensions "app"
// 依据flavors变动的话设置如下
productFlavors {
autoTest {
// Assigns this product flavor to the "version" flavor dimension.
// This property is optional if you are using only one dimension.
dimension "app"
manifestPlaceholders = [my_app_ame: "demo1", my_app_icon: "@mipmap/logo1"]
}
appStore {
// Assigns this product flavor to the "version" flavor dimension.
// This property is optional if you are using only one dimension.
dimension "app"
manifestPlaceholders =