在build.gradle设置debug与release版本的包名,即可实现版本共存。
android {
buildTypes {
debug{
versionNameSuffix "-debug" // 给版本名添加-debug 后缀
applicationIdSuffix ".debug" // 在 debug 构建类型中包名添加 ".debug" 后缀
}
...
}
...
}
如果需要给debug的安装包设置另外的名称,需要如下设置,并且删除strings.xml文件里面的app_name常量,否则编译出现重复常量无法通过。
android{
...
android.applicationVariants.all {
variant ->
variant.outputs.all {
//这里修改apk编译出来后的文件名
outputFileName = "smsPullService_v${defaultConfig.versionName}_${buildType.name}.apk"
}
if (variant.buildType.name == 'debug') {//这里指定app为debug版本
variant.resValue "string", "app_name", "appName(DEBUG)"
}else{//这里设置非debug版本为正常名称
variant.resValue "string", "app_name", "appName"
}
}
}