Skip to content

Instantly share code, notes, and snippets.

@DidahDx
Created August 2, 2021 06:40
Show Gist options
  • Select an option

  • Save DidahDx/c9f0c12ecb7ff9922871aa391077d257 to your computer and use it in GitHub Desktop.

Select an option

Save DidahDx/c9f0c12ecb7ff9922871aa391077d257 to your computer and use it in GitHub Desktop.
Customize Android apk names
android{
// Customize your APK name here
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.all { output ->
// def appId = variant.applicationId// com.exampleFree.app OR com.examplePaid.app
// def formattedDate = new Date().format('yyyy-MM-dd-HH-mm')
// def formattedDate = new Date().format('yyyy-MM-dd')
def versionName = variant.versionName
// def versionCode = variant.versionCode //e.g 1.0
// def flavorName = variant.flavorName //e.g. Free
def buildType = variant.buildType.name //e.g. debug
// def variantName = variant.name //e.g. FreeDebug
ext.revision = getGitRevParseInfo("--short")
ext.branch = getGitRevParseInfo("--abbrev-ref")
//customize your app name by using variables
outputFileName = "${appName}-${buildType}-${versionName}-${ext.branch}-${ext.revision}.apk"
}
}
}
static def getGitRevParseInfo(what) {
def cmd = "git rev-parse " + what + " HEAD"
def proc = cmd.execute()
proc.text.trim()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment