Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To change Android App Bundles name (app.aab) to reflect App version and build type

While I'm building an APK I can change APK name in build.gradle script, like that:

android.applicationVariants.all { variant ->
  if (variant.buildType.name != "debug") {
      variant.outputs.all {
          outputFileName = "${variant.applicationId}-v${variant.versionName}-${variant.name}.apk"
      }
  }
}

An I'll have something like this com.myapp.package-v1.x.x-release

Is there a way to do something similar with Android App Bundles, it is not convenient to always have app.aab

like image 969
Roman Nazarevych Avatar asked Feb 08 '19 13:02

Roman Nazarevych


People also ask

How can I change my AAB package name?

Press Ctrl + B and change the package name.

What is the difference between APK and AAB?

APK is the Android packaging format that users can install directly on their devices, whereas AAB is a publishing format that developers provide to Google.


1 Answers

I have come up with the solution of how to achieve this with Gradle.

First, we have to create in App build.gradle file a Gradle task that will rename the original app.aab on copy. This method is described here. Then for conveniance, we will add another method that will delete old app.aab file.

android{ 
.....
}
dependencies{
.....
}
.....

task renameBundle(type: Copy) {
    from "$buildDir/outputs/bundle/release"
    into "$buildDir/outputs/bundle/release"

    rename 'app.aab', "${android.defaultConfig.versionName}.aab"
}

task deleteOriginalBundleFile(type: Delete) {
    delete fileTree("$buildDir/outputs/bundle/release").matching {
        include "app.aab"
    }
}

In this example the output file name will be something like 1.5.11.aab Then we can combine those tasks together into publishRelease task which will be used for publishing the App:

task publishRelease(type: GradleBuild) {
    tasks = ['clean', 'assembleRelease', 'bundleRelease', 'renameBundle', 'deleteOriginalBundleFile']
}
like image 88
Roman Nazarevych Avatar answered Nov 15 '22 00:11

Roman Nazarevych