Rename output APK

This commit is contained in:
Awin Huang
2024-05-16 16:53:54 +08:00
parent 9a20f429ea
commit 897109bfa9

View File

@@ -31,6 +31,29 @@ android {
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
} }
applicationVariants.all{
variant ->
variant.outputs.each{
output->
// on below line we are specifying our app name.
project.ext { appName = 'kirbyTestApp' }
// on below line we are adding the formatted date to our apk file name.
def formattedDate = new Date().format('yyyyMMdd')
// on below line we are creating a new name for our apk.
def newName = output.outputFile.name
// on below line we are replacing our previous name with our app name.
newName = newName.replace("app-", "$project.ext.appName-")
// 當build type為 debug時觸發
// on below line we are replacing -debug with our formatted date.
newName = newName.replace("-debug", "-debug-" + formattedDate)
// 當build type為 release時觸發
// on below line we are replacing -release with our formatted date.
newName = newName.replace("-release", "-release-" + formattedDate)
// at last we are setting our apk name to it.
output.outputFileName = newName
}
}
} }
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8