Created
November 15, 2022 09:53
-
-
Save omkar-tenkale/833272c217f847b38764e759475e49ad to your computer and use it in GitHub Desktop.
Change gradle android apk name
This file contains 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{ | |
... | |
def changeApkName = { variant -> | |
variant.outputs.each { output -> | |
def apk = output.outputFile; | |
def addBrand = true | |
def addTime = false | |
def addGitBranch = true | |
def addVersionCode = true | |
def addVersionName = true | |
def newName = ""; | |
if(addBrand){ | |
newName += rootProject.name | |
} | |
if(addGitBranch){ | |
newName += "-"+getGitRevParseInfo("--abbrev-ref") | |
} | |
if(addTime){ | |
newName += ("-"+new Date().format('h-m-aa')) | |
} | |
if(addVersionCode){ | |
newName += ("-v" + variant.mergedFlavor.versionCode) | |
} | |
if(addVersionName){ | |
newName += ("(" + variant.mergedFlavor.versionName + ")") | |
} | |
if(variant.buildType.name == "release"){ | |
newName += "-release.apk"; | |
}else{ | |
newName += ".apk"; | |
} | |
if (!output.zipAlign) { | |
newName = newName.replace(".apk", "-unaligned.apk"); | |
} | |
output.outputFileName = newName; | |
println 'INFO: Set outputFile to ' + output.outputFile + " for [" + output.name + "]" | |
} | |
} | |
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