zaxunobi
zaxunobi

Reputation: 940

Sharing code for root version and rootless version with flavors

I have two almost identical android projects that performs some tasks (heavy ones since I am using openCV) with the use of root permissions or simply without root. I want to use flavors since it gets boring handling two projects.

I have plenty of classes that are identical, regardless of the flavor, so I want to share those classes with both flavors. For classes/files that are unique (like MainActivity, layouts and AndroidManifest ) I would like of course to have each file for flavor.

 flavorDimensions "default"

 productFlavors {

        freeVersion {
            dimension "default"
            applicationIdSuffix ".root"
        }

        proVersion {
            dimension "default"
            applicationIdSuffix ".rootless"
        }
    }

  sourceSets {
        RootFlavor {
            res {
                srcDirs 'src/RootFlavor/res'
            }
            java {
                srcDirs 'src/RootFlavor/java'
            }
        }
        RootlesFlavor {
            res {
                srcDirs 'src/RootlesFlavor/res'
            }
            java {
                srcDirs 'src/RootlesFlavor/java'
            }
        }

But for some reason the folders don't appear in my project. Furthermore this way I would need also to have redundant classes (the ones that are identical) in each src subfolder. So how to achieve what I am saying?

Edit:

Let's say I have Classes A, B, C, D, E, F. I want to share classes A, B, C and D for both flavors. Class E for RootFlavor and and Class F for RootlessFlavor.

Upvotes: 0

Views: 33

Answers (0)

Related Questions