Build flavors for different version of same class

Since you have the classes under 2 different packages, these are totally different classes. So the classes aren’t replacing each other.

With flavors, you can’t override class files. So, one way to accomplish what you want is move these classes out of main, and into flavorA.

So you would have something like this:

project/
   |
   |---src/
        |---flavorA2/
        |      |
        |      |---java/
        |      |     |---com.abc
        |      |                 |-----classA.java
        |      |                 |-----classB.java
        |      |---res/
        |      |---AndroidManifest.xml
        |
        |---main/
        |      |---java/
        |      |     |---com.abc.flavorA
        |      |                 |-----classC.java
        |      |                 |-----classD.java
        |      |---res/
        |      |    |---drawable/
        |      |    |---layout/
        |      |    |---values/
        |      |         
        |      |---AndroidManifest.xml
        |
        |---flavorA/
        |      |---java/
        |      |     |---com.abc
        |      |                 |-----classA.java
        |      |                 |-----classB.java

This way, whenever you pick a flavor, only one version of ClassA and ClassB will be visible.

Leave a Comment