Skip to content

Instantly share code, notes, and snippets.

@Qw4z1
Last active November 4, 2015 08:55
Show Gist options
  • Save Qw4z1/a8312dbb571e0dd28696 to your computer and use it in GitHub Desktop.
Save Qw4z1/a8312dbb571e0dd28696 to your computer and use it in GitHub Desktop.
APK file naming. Put in base directory of the project and add 'apply from: 'artifacts.gradle'' to the apps build.gradle. All credit goes to Erik Ogenvik at Jayway for his blog post http://www.jayway.com/2015/03/13/producing-better-named-android-apks-with-gradle/
android.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.each {output ->
def newApkName
//If there's no ZipAlign task it means that our artifact will be unaligned and we need to mark it as such.
if (output.zipAlign) {
newApkName = "${appName}-${output.baseName}-${variant.versionCode}.apk"
} else {
newApkName = "${appName}-${output.baseName}-${variant.versionCode}-unaligned.apk"
}
output.outputFile = new File(output.outputFile.parent, newApkName)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment