Created
August 2, 2021 06:40
-
-
Save DidahDx/c9f0c12ecb7ff9922871aa391077d257 to your computer and use it in GitHub Desktop.
Customize Android apk names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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