Skip to content

Instantly share code, notes, and snippets.

@omkar-tenkale
Created November 15, 2022 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omkar-tenkale/833272c217f847b38764e759475e49ad to your computer and use it in GitHub Desktop.
Save omkar-tenkale/833272c217f847b38764e759475e49ad to your computer and use it in GitHub Desktop.
Change gradle android apk name
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