I\'d like to change \"app-release.apk\" file name to like following when I build an app by using gradle.
[format] (appname of package name)_V(version code)_(yyMMdd)_(
Update: Please check Anrimian's answer below which is much simpler and shorter.
Try this:
gradle.properties
applicationName = MyApp
build.gradle
android {
...
defaultConfig {
versionCode 111
...
}
buildTypes {
release {
...
applicationVariants.all { variant ->
renameAPK(variant, defaultConfig, 'R')
}
}
debug {
...
applicationVariants.all { variant ->
renameAPK(variant, defaultConfig, 'T')
}
}
}
}
def renameAPK(variant, defaultConfig, buildType) {
variant.outputs.each { output ->
def formattedDate = new Date().format('yyMMdd')
def file = output.packageApplication.outputFile
def fileName = applicationName + "_V" + defaultConfig.versionCode + "_" + formattedDate + "_" + buildType + ".apk"
output.packageApplication.outputFile = new File(file.parent, fileName)
}
}
Reference: https://stackoverflow.com/a/30332234/206292 https://stackoverflow.com/a/27104634/206292