Skip to content

Instantly share code, notes, and snippets.

@benvium
Created April 21, 2016 14:03
Show Gist options
  • Save benvium/c1ddbac37f6b6be23a575bead4831769 to your computer and use it in GitHub Desktop.
Save benvium/c1ddbac37f6b6be23a575bead4831769 to your computer and use it in GitHub Desktop.
Gradle code to make APK files have a sensible format
// Makes the APKs we build be called AppName-release-buildVariant-1.2.3_4.apk
//
// To use, add this file to the root of your project (next to gradle.properties) make sure the name is artifacts.gradle.
// Then edit gradle.properties to include: `applicationName=MyAppName`
// Then edit module build.gradle, add at the end `apply from: "../artifacts.gradle"`
//
// Adapted slightly from https://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.versionName}_${variant.versionCode}.apk"
} else {
newApkName = "${appName}-${output.baseName}-${variant.versionName}_${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