gradle 版本:4.1 (gradle-4.1-all.zip)
在defaultConfig添加:
defaultConfig{
...
flavorDimensions "versionCode"
...
}
buildTypes中的配置:
buildTypes {
release {
signingConfig signingConfigs.release //设置签名信息
minifyEnabled true //混淆开启
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
manifestPlaceholders = [
APK_CHANEL:"Baidu Market"
]
applicationVariants.all { variant ->
if (variant.buildType.name == 'release') {
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def fileName = "release_v${defaultConfig.versionName}_${releaseTime()}_${variant.flavorName}.apk"
output.outputFileName = fileName
}
}
}
}
}
debug {
signingConfig signingConfigs.release
manifestPlaceholders = [
APK_CHANEL:"Baidu Market"
]
}
}
在buildTypes下面添加:
productFlavors{
baidu {
manifestPlaceholders = [
APK_CHANEL:"Baidu Market"
]
}
...
}
在最外层添加:
def releaseTime() {
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}
网友评论