Creating Customized Versions of Your Android App with Product Flavors.

Sirilmp
2 min readDec 17, 2022

--

from : https://mishry.com/wp-content/uploads/2021/02/Lays-Chips-Flavors.jpg

What are Android product flavors?

Product flavors in Android are custom versions of an app that are built using the same code base, but with different configurations and resources. They allow you to create multiple versions of your app that target different markets or audiences, without having to maintain separate code bases for each version.

For example, you might want to create a product flavor for a paid version of your app and another flavor for a free version with in-app purchases. Or, you might want to create separate flavors for different regions or languages.

How to create a product flavor.

To create a product flavor in Android, you will need to modify your app’s build.gradle file. First, you will need to specify the product flavors block and define a new flavor for your app. Here is an example of how you might define a product flavor for a paid version of your app:

productFlavors {
paid {
applicationId "com.example.paid"
resValue "string", "app_name", "Paid App"
}
}

In this example, we have defined a product flavor called “paid” with a unique application ID and a different app name. We could then specify additional resources, such as different icons or layouts, for this flavor in the corresponding res/ directory.

To build and install the paid flavor of your app, you can use the following command:

./gradlew assemblePaidDebug

You can also create multiple product flavors in the same app. For example, you might want to create separate flavors for different regions or languages. Here is an example of how you might define multiple product flavors in your build.gradle file:

productFlavors {
paid {
applicationId "com.example.paid"
resValue "string", "app_name", "Paid App"
}
free {
applicationId "com.example.free"
resValue "string", "app_name", "Free App"
}
english {
applicationId "com.example.english"
resValue "string", "app_name", "English App"
}
french {
applicationId "com.example.french"
resValue "string", "app_name", "French App"
}
}

To build and install the French version of the free flavor of your app, you can use the following command:

./gradlew assembleFreeFrenchDebug

Conclusion.

Product flavors are a powerful tool for creating customized versions of your Android app. They allow you to maintain a single code base, while providing different resources and configurations for different markets or audiences. By creating multiple product flavors, you can easily create and distribute different versions of your app to different users.

--

--