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
Press Ctrl + B and change the package name.
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.
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']
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With