Skip to content

Instantly share code, notes, and snippets.

@waleoyediran
Created August 20, 2016 09:37
Show Gist options
  • Save waleoyediran/187dbf323530c41cc39bb49fce0b3468 to your computer and use it in GitHub Desktop.
Save waleoyediran/187dbf323530c41cc39bb49fce0b3468 to your computer and use it in GitHub Desktop.
Gradle Plugin to help with apk naming using a combination of application name, variant and version number
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 = "app"
}
variant.outputs.each { output ->
def newApkName
//If there's no ZipAlign task it means that our artifacts will be unaligned and we need to mark it as such.
if (output.zipAlign) {
newApkName = "${appName}-${output.baseName}-${variant.versionName}.apk"
} else {
newApkName = "${appName}-${output.baseName}-${variant.versionName}-unaligned.apk"
}
//noinspection GroovyAssignabilityCheck
output.outputFile = new File(output.outputFile.parent, newApkName)
}
}
@waleoyediran
Copy link
Author

To use
Put the artifacts.gradle file in your project root.

In your build.gradle; add the line
apply from: "../artifacts.gradle"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment