打包设置
flavorDimensions("channel")
productFlavors {
demo {
manifestPlaceholders = [APP_NAME: "@string/app_name_demo"]
applicationId "com.example.demo"
buildConfigField 'String', 'SERVICE_ITEM', "\"0\""
dimension "channel"
}
release{
manifestPlaceholders = [APP_NAME: "@string/app_name"]
applicationId "com.example.release"
buildConfigField 'String', 'SERVICE_ITEM', "\"1\""
dimension "channel"
}
}
//自定义apk文件名
applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
// def npstr = android.buildTypes.release.minifyEnabled ? "" : "_np"
def flavor = variant.productFlavors[0]
def typeName
switch (flavor.name) {
case "demo":
typeName = "测试版"
break
case "release":
typeName = "正式版"
break
default:
break
}
outputFileName = "DEMO${releaseTime()}_v${flavor.versionName}_${typeName}.apk"
}
}
}
buildTypes {
debug {
// applicationIdSuffix ".debug"
manifestPlaceholders = [APP_NAME: "@string/app_name_debug"]
}
release {
manifestPlaceholders = [APP_NAME: "@string/app_name"]
// 是否进行混淆
minifyEnabled false
// 混淆配置文件
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
来源:oschina
链接:https://my.oschina.net/u/4270977/blog/4948711