EDIT: for modern versions of Gradle tools, use the @ptx variation (use output.outputFile instead of variant.outputFile :
android { applicationVariants.all { variant -> variant.outputs.each { output -> output.outputFile = new File(output.outputFile.parentFile, output.outputFile.name.replace(".apk", "${variant.versionName}.apk")); } } }
As with the Gradle plugin for tools version 0.14, you should use the following instead to properly support multiple output files (e.g., APK Splits):
android { applicationVariants.all { variant -> variant.outputs.each { output -> variant.outputFile = new File(variant.outputFile.parentFile, variant.outputFile.name.replace(".apk", "${variant.versionName}.apk")); } } }
For older versions:
Yes, we do this in our application. Just add the following to your android tag in build.gradle:
android { applicationVariants.all { variant -> def oldFile = variant.outputFile def newPath = oldFile.name.replace(".apk", "${variant.versionName}.apk") variant.outputFile = new File(oldFile.parentFile, newPath) } }
kcoppock Aug 12 '14 at 16:51 2014-08-12 16:51
source share