Create flavors of Android App on same CodeBase
In this post i will cover how to create flavors of android app like paid version and free version.
Problem with previous Solutions
- One way to do this is to create two codebase for your Android app. Problem with this is we have to maintain two different codebase for paid and free version which will a nightmare to maintain. If you make some change to one code then same has to be done with other code. This will be more problematic when this type of flavors increase.
- Other way people used to deal with this kind of problem by creating a library project for common codebase and then flavors can be created in the app which are using that library project. There were many problems related to that solution.
But with new Android Studio create flavors android app can be solved by using build flavor feature of gradle build system. You just have to create flavors of app which will pick code from common codebase and rest code from your flavor folder.
[su_button url=”https://github.com/androidsrc/AndroidAppFlavours” target=”blank” style=”stroked” background=”#51d461" color=”#ffffff” size=”6" center=”yes” radius=”0" icon=”icon: arrow-circle-o-down”]Download Full Source Code[/su_b[/su_button]p>
Steps to create App flavors
For this we have declare flavors in our gradle.build file in our app module. Let us assume we want to create 2 flavor of our app . One for free version and other for paid version. In this case we have to declare 2 flavors in gradle.build file. After that we can add flavor specific compilation related code there like debug info.
buildConfigField 'String', 'VAR', '"This is string from FREE build script"'
buildConfigField 'String', 'VAR', '"This one is from PAID build script"'