How to build different flavors of an Android project

It might happen that you will have multiple flavors of APKs. Usually gradle makes it very easy to select the flavor of the project by putting the flavor name to the specified place in the gradle task’s name.

Here is a simple and easy description of the build types(debug/release) and also there we have a note about build variants:

The “Debug” part in the above task names is just a camel-case version of the build variants name, so it can be replaced with whichever build variant you want to assemble or install. For example, if you have a “demo” product flavor, then you can build the debug version with the assembleDemoDebug task.

Also the configuration of flavors made really quick by gradle:

android {
    ...
    defaultConfig {...}
    buildTypes {...}
    productFlavors {
        demo {
            applicationIdSuffix ".demo"
            versionNameSuffix "-demo"
        }
        full {
            applicationIdSuffix ".full"
            versionNameSuffix "-full"
        }
    }
}

After you are sure about the flavor you will need, the only thing you need to change on Bitrise will be the gradle-runner step’s gradle task input.

Usually, if you need more than one of your variants in a single build, you can do two things:

  1. Use one gradle-runner step, with a simple assembleDebug (without any flavor, just the type is enough), so it will generate all the flavors, or just list the tasks separated by a space for example: assembleFlavor1Debug assembleFlavor2Debug
  2. Use multiple gradle-runner step, so you can define the exact flavors you need, for example: assembleFlavor1Debug in the first gradle-runner, and assembleFlavor2Debug in the second, the point of using separated gradle-runner step is that this way the env $BITRISE_APK_PATH after the gradle-runner step will contain the only flavor just built. For example: /path/to/my/flavor1-debug.apk and /path/to/my/flavor2-debug.apk So this way Sign APK and Google Play Deploy steps can automaticall pick up the APK to work with. :wink:

Feel free to ask any questions! :rocket::slightly_smiling_face:

2 Likes

Cool. What would you put in the “package name” in the deploy to google step if you use something like assembleRelase in your gradle runner step which creates a bunch of flavours with different package names?

1 Like

Hi @Jyllands-Posten,

The “package name” input field specifies the app ID in Google Play, it is not strictly connected to your build output artifacts.

In case of multiple build variants, you would specify the actual APK tp upload in the “APK path” input.

Did that answer your question? :slight_smile:

I guess it did. I ended up doing a fork of the google deploy step which uses aapt to resolve the package names of the apk files, then uploads them one by one…

Hi, how do we change build version numbers for multiple flavors?

@anupamchugh The Change version number step works by updating versionCode and versionName in your build.gradle config file, so building any flavor after this step will use the updated version number.

Hi,
I’ve tried it and it looks like it builds the right flavor but with wrong assets (drawables etc are taken from another flavor).
Am I missing something?

Hello @doron.s :wave:

In case you still experience this issue, could you please submit a ticket to us with all the details you can provide at https://support.bitrise.io/?

Please make sure to send us the URL of a related build and enable Support User so we can take a closer look! :slightly_smiling_face: