Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify different SigningConfigs for 'assemble' and 'bundle'?

Tags:

gradle

I have an app where I need to be able to build apk files for testing, and aab files for uploading to the play store. The apk and aab files should be signed with different keys.

How can I specify different signingConfig blocks depending on whether the build is run with assembleRelease vs. bundleRelease? It seems like this should be a flavor-like thing but I can't figure out how.

like image 542
2 revs, 2 users 78% Avatar asked Nov 15 '25 10:11

2 revs, 2 users 78%


1 Answers

You can create a new build type say "store" in addition to "debug" and "release", and give the store build type the required signing config:

android {
    buildTypes {
        register("store") {
            initWith(buildTypes["release"])
            matchingFallbacks.add("release")
            signingConfig = signingConfigs.create("store") {
                ...
            }
        }
    }
}

Then:

./gradlew :app:assembleRelease :app:bundleStore

From https://developer.android.com/studio/build/build-variants (emphasis mine):

For example, a "demo" product flavor can specify different features and device requirements, such as custom source code, resources, and minimum API levels, while the "debug" build type applies different build and packaging settings, such as debug options and signing keys.

like image 76
SK9 Avatar answered Nov 17 '25 08:11

SK9



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!