需求1:根据渠道不同给包名添加不同的后缀名
方案:
//先定义默认包名,用来复用
def packageName = "xxx.xxxx.xxxx"
defaultConfig {
applicationId packageName
...
}
productFlavors {
aibei {}
google {}
pure {}
qiji {}
anzhi { applicationId packageName + ".anzhi" }
baidu { applicationId packageName + ".bd" }
coolpad { applicationId packageName + ".coolpad" }
cps {}
gionee { applicationId packageName + ".jinli" }
huawei { applicationId packageName + ".HUAWEI" }
lenovo { applicationId packageName + ".lenovo" }
m4399 { applicationId packageName + ".m4399" }
meizu { applicationId packageName + ".mz" }
oppo { applicationId packageName + ".nearme.gamecenter" }
qihoo360 {}
samsung { applicationId packageName + ".samsung" }
tencent {}
uc { applicationId packageName + ".uc" }
vivo { applicationId packageName + ".vivo" }
xiaomi {}
yunos {}
}
打出apk后使用命令检查是否修改包名成功
aapt dump badging xx.apk | findstr package
//将xx.apk替换掉
结果如下
修改成功
需求2:修改生成的apk文件名
release {
minifyEnabled false
signingConfig signingConfigs.release
buildConfigField("boolean", "RC", "false")
applicationVariants.all { variant ->
variant.outputs.each { output ->
//talkingtomadventure-uc-b102-v1.1.1(b后面为打包号)
output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace("release", "b001-v" + versionName + "-release"))
}
}
}
修改replace里面的内容即可
欢迎关注我的微信公众号:安卓圈