In modern application development, we follow some cycles to build and release our products. We often need multiple variants of our applications for multiple sets of audiences.
Recently I came across a situation where I was building some features in my app and I had to share multiple apks multiple times to multiple team members for testing during the development process.
I realized that I needed 3 types of builds at that moment:
1. Development build which needs to be shared within development team (least stable).
2. Staging build which needs to be shared with other team members for stability test (should be stable🤞).
3. Production build which needs to be on the play store (most stable).
All these different builds required different API Base URLs, config keys, etc. which can mess a lot of things by keeping on editing them before every build.
In this case, adding build flavors to my project saved my life 😌.
Now I will show you a step by step guide to add flavors to your project.
Open your build.gradle file (app level) and you will have a similar android block.
By default, you may not find debug inside buildTypes but you can add it there.
Right now if you will open the build variants panel you will find something like this:
By default, we have only two build variants, i.e; debug and release.
Now set flavorDimensions to default and add three product flavors.
It’s time to add some stuff like application ids, various keys, etc. to each of them which will be used at the time of compilation.
In this example, I have added separate application ids, so that my android device can differentiate and install them separately.
Separate app names are set along with separate buildConfigFields.
Now, hit sync now and open the build variants panel again and you will have something like this
Now you have 6 build variants, 2 for each. You just now have to switch between different variants and make a build. Android studio will automatically compile your build with respective buildConfig values.
I have installed debug builds of each of them on my device and they will act as different apps due to different application ids.
That’s it for this article. Thanks for reading. See you in the next one!
You can connect me on LinkedIn here