Created
June 11, 2014 06:56
-
-
Save stefanhoth/faedeb4c58615992937d to your computer and use it in GitHub Desktop.
AndroidDev / gradle: How to rename your output apk during build time to include details like the version.
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 { | |
// .. set up build flavors etc here | |
//instead of "app-release.apk" this method will rewrite the name to | |
// "MyCoolCompany-MyGreatProduct-v<defaultConfig.versionName>-RELEASE.apk which is much better suited for archiving and overall handling | |
// To restore the default behavior just delete the whole block below | |
applicationVariants.all { variant -> | |
def apk = variant.outputFile; | |
def newName; | |
newName = apk.name.replace(".apk", "-v" + defaultConfig.versionName + "-" + variant.buildType.name.toUpperCase() + ".apk"); | |
newName = newName | |
.replace("-" + variant.buildType.name, "") | |
.replace(project.name, "MyCoolCompany-MyGreatProduct"); | |
variant.outputFile = new File(apk.parentFile, newName); | |
if (variant.zipAlign) { | |
variant.outputFile = new File(apk.parentFile, newName.replace("-unaligned", "")); | |
} | |
logger.info('INFO: Set outputFile to ' + variant.outputFile + " for [" + variant.name + "]"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please be aware that your CI probably doesn't know about the name change. It might be necessary to copy the output files after creation rather than renaming them in order to keep your build chain intact.