在app/build.gradle文件上增加下面信息:
...
android {
...
buildTypes {
release {
...
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
output.outputFile.name.replace(output.outputFile.name, "lingshi_${variant.buildType.name}_v${variant.versionName}_${releaseTime()}.apk"))
}
}
}
}
...
}
...
def releaseTime() {
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}
- variant.buildType.name:为编译类型release或debug;
- variant.versionName:为版本号;
- releaseTime():为编译时间;