foreword
Android uses Gradle for packaging when packaging. You can build.gradle
rename the output apk file in the model file, and add the version number and packaging time to the file name.
sample code
The build.gradle file is written in the grooy language, in which we can define the current packaging time:
def createTime = new Date().format("YYYYMMddhhmm", TimeZone.getTimeZone("GMT+08:00"))
Then we can customize the file name by adding the following configuration in the
model file :build.gradle
android{
...
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (variant.buildType.name == 'release') {
//可自定义自己想要生成的格式
//Demo1-Production-v1.0.1-202112070536 格式
def createTime = new Date().format("YYYYMMddhhmm", TimeZone.getTimeZone("GMT+08:00"))
def fileName = "Demo1-Production-v${android.defaultConfig.versionName}-${createTime}.apk"
output.outputFileName = new File(outputFile.parent, fileName).name
} else {
def fileName = "Demo1-${variant.buildType.name}-v${android.defaultConfig.versionName}.apk"
output.outputFileName = new File(outputFile.parent, fileName).name
}
}
}
}