Skip to content

Instantly share code, notes, and snippets.

@zhuixinjian
Created June 12, 2015 05:49
Show Gist options
  • Select an option

  • Save zhuixinjian/ce9f853125132ffa55cd to your computer and use it in GitHub Desktop.

Select an option

Save zhuixinjian/ce9f853125132ffa55cd to your computer and use it in GitHub Desktop.
rename output apk
def releaseTime() {
return new Date().format("yyyyMMdd-hhmm", TimeZone.getDefault())
}
android{
android.applicationVariants.all { variant ->
def appName
//Check if an applicationName property is supplied; if not use the name of the parent project.
if (project.hasProperty("applicationName")) {
appName = applicationName
} else {
appName = parent.name
}
variant.outputs.each { output ->
def versionName = variant.versionName //4.0.0
def versionCode = variant.versionCode //4.0.0
def targetName = variant.productFlavors.get(0).name //dev
def adName = variant.productFlavors.get(1).name //free,pro
def buildName = variant.buildType.name //release
def outputFile = output.outputFile //
if (buildName == 'release' && outputFile != null){
def fileName = "${appName}-${targetName}-${adName}-V${versionName}-${versionCode}-${buildName}-${releaseTime()}.apk"
def outputDir = OUT_DIR + "/" + versionName
output.outputFile = new File(outputDir, fileName)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment