Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the generated filename for App Bundles with Gradle?

So to change the generated APK filename inside gradle android I could do something like:

applicationVariants.output.all {     outputFileName = "the_file_name_that_i_want.apk" } 

Is there a similar thing for the generated App Bundle file? How can I change the generated App Bundle filename?

like image 772
Archie G. Quiñones Avatar asked Sep 26 '18 01:09

Archie G. Quiñones


People also ask

Where is the application gradle file?

gradle file is located inside your project folder under app/build. gradle.

What is bundle gradle?

Gradle Bundle Plugin allows you to create OSGI bundles.

Where is settings gradle file in Android Studio?

In Eclipse, select File > Export. In the window that appears, open Android and select Generate Gradle build files. Select the project you want to export for Android Studio and click Finish.


2 Answers

You could use something like this:

defaultConfig {   applicationId "com.test.app"   versionCode 1   versionName "1.0"   setProperty("archivesBaseName", applicationId + "-v" + versionCode + "(" + versionName + ")") } 
like image 81
SaXXuM Avatar answered Sep 24 '22 01:09

SaXXuM


As a more generic way to Martin Zeitlers answer the following will listen for added tasks, then insert rename tasks for any bundle* task that gets added.

Just add it to the bottom of your build.gradle file.

Note: It will add more tasks than necessary, but those tasks will be skipped since they don't match any folder. e.g. > Task :app:renameBundleDevelopmentDebugResourcesAab NO-SOURCE

tasks.whenTaskAdded { task ->     if (task.name.startsWith("bundle")) {         def renameTaskName = "rename${task.name.capitalize()}Aab"         def flavor = task.name.substring("bundle".length()).uncapitalize()         tasks.create(renameTaskName, Copy) {             def path = "${buildDir}/outputs/bundle/${flavor}/"             from(path)             include "app.aab"             destinationDir file("${buildDir}/outputs/renamedBundle/")             rename "app.aab", "${flavor}.aab"         }          task.finalizedBy(renameTaskName)     } } 
like image 23
David Medenjak Avatar answered Sep 24 '22 01:09

David Medenjak