Product Flavors in Android : (Part 1)

Milan Vadhel
3 min readApr 18, 2021

Hello everyone, In this article, we will learn about product flavors in android.
But before we move on to product flavors we need to know some basics. So Let’s Begin…

What is build type?

  • In Android whenever you are creating a new project the IDE will generate debug and release build types by default.
  • You can understand it as different versions of your app.

What is product flavor in android?

  • The simple meaning of the product flavors is that same product with different flavors.
  • In Android development, product flavors can consider as different versions of your app.

Examples 1: If you want to make your app by providing different features for your free users and paid users.

So you need to make two flavors. One is Free and another one is Paid.

Example 2: If you want to make your app with different color themes like Orange, White, and Green.

So you need to make three flavors. Orange, White, and Green. Each flavor contains its own res directory to differentiate its resource files which you want to use for different colors.

Example 3: If you want to make your app for different regions then you need a different flavor for respective regions like India, US, etc.

Example 4: Same as for Alpha and Beta version. You need two flavors Alpha and Beta.

Example 5: If you need to make your app with different API URLs like Staging, Prod, and Release.

Why do we need to use product flavors?

As per the above examples first time you thought that make different projects for each app version and change only required files, Right? Yes, But when your app becomes more complex it hards to maintain different projects for the same product with different features.

So the advantage of the product flavor is that you can make different versions of your app with different environments, different features with a single code base.

So the product flavor is also used for white labeling or rebranding the same product with different colors. Like one e-commerce app with blue color and the other one is with white color. You can also change the app icon based on different flavors.

What is the flavor dimension?

Flavor dimensions are nothing but grouping your product flavors with different environments.

What is Build Variant?

  • Android Build Variants combine build types and product flavors. They create a matrix of all combinations.
  • Build variants do cartesian product to make different variants.

Example :

Your Build Types Are: debug and release
Your Product Flavors Are: Free and Paid

Then Your Build Variants are :
freeDebug
freeRelease
paidDebug
paidRelease

You can select the build variant which you want to run from the left side panel.

When you run and install both free and paid version on your device. You can see there are two apps free version and paid version.

You can also check the version name and APK name from app info. It is different based on which build you have run.

So finally, we have done.

Thank you guys for reading my article. I hope it will help you to understand the concept behind the product flavors in Android.

In the next part, we will see how to set the different color themes for different flavors.

--

--