Applications are developed using some arbitrary values for development and QA. But, when it comes to production or releasing a new update for app, we need to change those arbitrary values to actual values.
For instance, take an application using web services, which requires some input from user and store it in database. During development and testing, many valid but arbitrary values are provided. And, we don’t want those values inside production database. So, an option is to keep different URL for different purposes.
But, there is another problem. We need to update our application (web service url) each time we create a build for development, QA and production.
For this type of problem productFlavors comes to our rescue.
In Android Studio project, open build.gradle of the module.
In it, inside android block, add productFlavors.
Now, create three directories inside
Based on the requirements, create java and res directories inside all three. If you don’t need any resource specific to the flavors then skip creating res.
Now, create package inside each java and keep the java code there which are specific to that flavor.
I have uploaded a demo application project on GitHub FlavourUsage. Clone, fork, modify and create your own flavor specific application.