How to build different flavors of an Android project

gradle
android

#1

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:

https://developer.android.com/studio/build/building-cmdline.html

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:

https://developer.android.com/studio/build/build-variants.html#product-flavors

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:


How do generate Android APKs by build variants?
#2

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?