An elephant taking a bath
“Gradle” taking a mud bath — Photo by Andrew Rice on Unsplash

Understanding Build Variants in Gradle Android

Yudanto Anas Nugroho
2 min readOct 23, 2020

Sometimes in app development there’s a time when we want to build a demo app for our users. That’s when build variant comes into play.

Each build variant represents a different version of our app. For example, some of the premium games that are published in the app store may have a trial/demo version so that new users could have a glimpse of experience before they end up paying. We can also build different versions of your app that target different devices, based on API level or other device variations.

In build variant, there are terms such as build types and product flavours. Build Type refers to build and packaging settings like signing configuration for a project. For example, debug and release build types. The debug will use android debug certificate for packaging the APK file. While, release build type will use user-defined release certificate for signing and packaging the APK.
On the other hand, a (product) flavour is used to specify custom features, minimum and target API levels, device and API requirements like layout, drawable and custom code.

Example of Build Types in an app

In the above example there are 2 types of build type, release and debug. Usually, the debug type have a “debuggable” property set to true, which is meant that Android Studio could have a debuggable apk. To learn more about all the properties you can configure with build types, click here.

Example of Product Flavours

Same thing happen here, when we want to create a product flavour firstly we have to create a least one flavor dimensions. After that we have to assign each flavour with its dimension. Finally, when we are ready to sync gradle in Android Studio, it will generate 4 kinds of apk like so:

  • app-demo-debug.apk
  • app-full-debug.apk
  • app-demo-release.apk
  • app-full-release.apk

That’s it! Build Variant is pretty helpful not only make your app more versatile and robust but also manageable because we can differentiate each versions by its features, content, API compabilty and more. Furthermore, we can even put different resources in specific versions of our app. Read more about creating source sets in Android Developer Guide.

Thank you and have a good one!

--

--