Skip to content

Instantly share code, notes, and snippets.

@faruktoptas
Created October 22, 2015 08:25
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 faruktoptas/e2bcb4796ce4e63c75e6 to your computer and use it in GitHub Desktop.
Save faruktoptas/e2bcb4796ce4e63c75e6 to your computer and use it in GitHub Desktop.
Rename output apk file (append versionName)
android {
// ....
applicationVariants.all { variant ->
renameApk(variant, defaultConfig)
}
}
// ---------------------------
def renameApk(variant, defaultConfig) {
variant.outputs.each { output ->
if (output.zipAlign) {
def file = output.outputFile
def fileName = file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk")
output.outputFile = new File(file.parent, fileName)
}
def file = output.packageApplication.outputFile
def fileName = file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk")
output.packageApplication.outputFile = new File(file.parent, fileName)
}
}
@olddustysocksunderthecouch

This doesnt work the code in rename can't be abstracted into a method

@haies
Copy link

haies commented Apr 16, 2021

Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated

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