We’ll teach you how to make Android product flavors programmatically using Android Studio and Gradle build tool. You can use this technique to create duplicate Android apps or Android app clones. This is an advanced tutorial.We often have to launch similar apps for different markets, countries or niches. Same Android mobile game can become different over holiday seasons to accommodate product placement or a social event. Similarly, due to copy rights we may have to make slight changes to an app before launching it in another country.In such a case, there may be a strong inclination among the mobile app developer to create multiple versions from scratch or be willing to charge twice or thrice the original cost from the client. With Android product flavors, this cost can be saved and further invested in bringing more advanced app features or new concepts to market.Android product flavors also known as Android build types or Android build variants are the native Android app development way to implement different versions of the same application with minor changes provided by Gradle and Android Studio together. Here is the official Android documentation for configuration of Android product flavors.
By following this tutorial, we are hopeful that you have understood basics of using Android product flavors/build variants. Send an email below if you need help in your app to create product flavors. You can also hire Android developers with us.
What are Android product flavors?
Android product flavors are for different types of the same application with just configuration changes like staging and production environment.By default there are two build types available in android studio project i.e.- Debug
- Release
Why do we need Android product flavors?
As a mobile application developer, you can have a scenario where you would like to release a new application from your previous project with some minor changes like app icon, theme, name or anything else. For this purpose, we have two approaches- Copy the whole project to create a new one, do change and release another app.
- Only change the required files having same base code and release another app.
How to create Android product flavors?
Let’s say we have an application with three different flavors* i.e.- Mango
- Blueberry
- Orange
- Package name
- Version name
- Version code
- Main layout
- Theme color
- App name
Steps to implement Android product flavors
Step 1
Create an application with basic functionality.Step 2
Define build variants in Gradle like shown below.And sync the Gradle.Step 3
After that in project structure view create three directories under app/src and name them exactly same as product flavors in GradleStep 4
Now create sub directories with same hierarchy as in main folder to add new layouts, drawable and values for different flavors.Step 5
Now you have three different flavors of same applicationTo change the build variant, Android Studio uses: select Build > Select Build Variant in the menu bar (or click Build Variants in the windows bar), and then select a build variant from the drop-down menu.Now change build variant from drop down menu and run application you have three different versions of same application (Screenshots attached).Code Snippet
Build types
buildTypes {
debug {
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard rules.pro'
}
}
Product flavors
productFlavors {
mango {
applicationId "com.therightsw.mango"
versionCode 1
versionName "1.0"
}
blueberry {
applicationId "com.therightsw.blueberry"
versionCode 1
versionName "1.0"
}
orange {
applicationId "com.therightsw.orange"
versionCode 1
versionName "1.0"
}
}
By following this tutorial, we are hopeful that you have understood basics of using Android product flavors/build variants. Send an email below if you need help in your app to create product flavors. You can also hire Android developers with us.