How to rename the app Bundle name from Android gradle with multiple product flavors?
Asked Answered
T

2

3

As I was able to rename the APK using this way but could not get how to rename App Bundle with multiple flavors.

android.applicationVariants.all { variant ->
    variant.outputs.all { output ->
        output.outputFileName = "${variant.getFlavorName()}-${variant.buildType.name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}-${output.getFilter(com.android.build.OutputFile.ABI)}.apk"
    }
}

Here are my app flavors and split APK code

productFlavors {
    aFlavor {
        applicationId "com.a"

        
        versionCode 5
        versionName "1.0.5"

        signingConfig signingConfigs.signingA
    }
    bFlavor {
        applicationId "com.b"

        versionCode 5
        versionName "1.0.5"

        signingConfig signingConfigs.signingB
    }
    cFlavor {
        applicationId "com.c"

        versionCode 3
        versionName "1.0.3"

        signingConfig signingConfigs.signingC
    }
}

splits {
    abi {
        enable true
        reset()
        include 'arm64-v8a', 'x86', 'x86_64'
        universalApk false
    }
}
Touchandgo answered 17/5, 2022 at 15:22 Comment(0)
C
2

Try this approach:

applicationVariants.all { variant ->
    variant.outputs.all { output ->
        output.outputFileName = "${variant.getFlavorName()}-${variant.buildType.name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}-${output.getFilter(com.android.build.OutputFile.ABI)}.apk"
    }

    tasks.named("sign${variant.name.capitalize()}Bundle", com.android.build.gradle.internal.tasks.FinalizeBundleTask) {
        File file = finalBundleFile.asFile.get()
        File finalFile = new File(file.parentFile, "${variant.getFlavorName()}-${variant.buildType.name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}.aab")
        finalBundleFile.set(finalFile)
    }
}

It uses an internal gradle task FinalizeBundleTask which has getter and setter for final bundle file name.

Cirilla answered 23/8, 2023 at 12:31 Comment(0)
F
-1

This is how I made and it works, try please

applicationVariants.all { variant ->
        variant.outputs.all {
            def flavor = variant.name
            def versionName = variant.versionName

            project.ext { appName = 'myApp' }
            def formattedDate = new Date().format('dd-MM_HH-mm')

            outputFileName = "${project.ext.appName}_${formattedDate}_v${versionName}_${flavor}.apk"
        }
    }
Fullblown answered 17/5, 2022 at 15:36 Comment(1)
It does not work for .aab filesScone

© 2022 - 2025 — McMap. All rights reserved.