Search code examples
javaandroidandroid-studiogradleandroid-productflavors

Using the Gradle flavor in Android Studio


I want to make an Android App with two different versions.

This is what I want to achieve

Main Screen calls a method in the Class named Execute

Now I want to have two different version of Execute class. Let's call the first one Flavor1 and the second version as Flavor2. Flavor1 will need the help of a library called Test1. Whereas the Flavor2 Execute class will need the Help of library called Test2.

Now what I am trying to achieve is when I try to build the Flavor1 then Test 2 library should NOT be included in the APK file. And when I build the Flavor2 then the Test1 library should NOT be included in APK file.

So this is the Scenario

Main Class --> Execute Class

Execute Class(Flavor1)-->Test1 Library

Execute Class(Flavor2)-->Test2 Library

Building Flavor1 should not contain Test2 Library

Building Flavor2 Should not contain Test1 Library

Is there any way to achieve this. Any Help would be grateful.


Solution

  • If you have defined flavors appropriately you can have flavor specific implementations as following :-

    say I have two different app-compat versions as per flavors

    flavorOneImplementation 'com.android.support:appcompat-v7:27.0.2'
    flavorTwoImplementation 'com.android.support:appcompat-v7:24.2.0'