0

I need to transfer the code version number from build.gradle in the filename .apk. For example, app-release_v3.apk.

Please help to find a solution. Thank you!

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841

2 Answers2

0

In build.gradle of the app module

android {
   ...

   defaultConfig {
      ...

      archivesBaseName = "MyAppName_v${versionName}"
   }
}  

As result you will have MyAppName_v3-release.apk

Eugene Krivenja
  • 647
  • 8
  • 18
  • Thanks for the answer! This works for the "Generate Signed APK"? I've updated the code, but the file still has the old name (( – Aleksey Krekotnev Apr 13 '16 at 08:04
  • This variant helped me: android { applicationVariants.all { variant -> variant.outputs.each { output -> output.outputFile = new File( output.outputFile.parent, output.outputFile.name.replace(".apk", "-${variant.versionName}.apk")) } } } – Aleksey Krekotnev Apr 13 '16 at 08:11
  • Yes, it works for the "Generate Signed APK". I am using it in all my projects. – Eugene Krivenja Apr 13 '16 at 09:16
0

You can use the "archivesBaseName" properties in your build.gradle file.

Somenthing like:

defaultConfig {

   project.ext.set("archivesBaseName", "app-xxx." + defaultConfig.versionName);

}
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841