Created
April 6, 2021 09:59
-
-
Save huutho-dev/5997af0eac08bc118b1e3c3ea24f906f to your computer and use it in GitHub Desktop.
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
| def branchNameCmd = 'git rev-parse --abbrev-ref HEAD'; | |
| def userNameCmd = 'git config user.name'; | |
| def getInfoFromGit(whatCommand) { | |
| def gitBranch = "Unknown branch" | |
| try { | |
| def workingDir = new File("${project.projectDir}") | |
| def result = whatCommand.execute(null, workingDir) | |
| result.waitFor() | |
| if (result.exitValue() == 0) { | |
| gitBranch = result.text.trim().replaceAll(" ","") | |
| } | |
| } catch (e) { | |
| } | |
| return gitBranch | |
| } | |
| def changeApkName = { variant -> | |
| variant.outputs.each { output -> | |
| def apk = output.outputFile; | |
| def newName = "[Chex]"; | |
| def branch = getInfoFromGit(branchNameCmd); | |
| def userName = getInfoFromGit(userNameCmd); | |
| if (variant.buildType.name == "release") { | |
| newName += "-" + branch + "[v" + variant.mergedFlavor.versionName + "]-release.apk"; | |
| } else { | |
| newName += "-" + branch + "-" + userName + "[v" + variant.mergedFlavor.versionName + "].apk"; | |
| } | |
| if (!output.zipAlign) { | |
| newName = newName.replace(".apk", "-unaligned.apk"); | |
| } | |
| output.outputFileName = new File(apk.parentFile, newName).getName(); | |
| println 'INFO: Set outputFile to ' + output.outputFile + " for [" + output.name + "]" | |
| } | |
| } | |
| android { | |
| applicationVariants.all { variant -> | |
| variant.outputs.each { output -> | |
| changeApkName(variant) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment