Android Gradle 多版本多APK打包,图标不同,包名不同, 修改apk名字
app build.gradle
buildConfigField 如果是String,字符串要多加单引号
android {
productFlavors {
kaifa {
versionCode 2
versionName '1.0.2'
buildConfigField("int", "VERSION", '2')
buildConfigField("boolean", "ISTATION", "true")
buildConfigField('String', "APK_NAME", '"开发版本"')
applicationId "com.test1"
resValue "string", "app_name", "开发版本"
resValue "string", "push_key", "111"
manifestPlaceholders = [app_name:"开发版本名称"]
}
ceshi {
versionCode 1
versionName '1.0.0'
buildConfigField("int", "VERSION", '1')
buildConfigField("boolean", "ISTATION", "false")
buildConfigField('String', "APK_NAME", '"测试版本"')
applicationId "com.test2"
resValue "string", "app_name", "测试版本"
resValue "string", "push_key", "555"
manifestPlaceholders = [app_name:"测试版本名称"]
}
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFileName = variant.productFlavors[0].manifestPlaceholders.get("app_name") + "_" +
variant.versionName + "_" +
variant.buildType.name + "_" +
variant.flavorName + "_" +
new Date().format("yyyyMMdd", TimeZone.getTimeZone("UTC")) +
".apk"
}
}
}