Question

I am building 2 flavours in my project and these flavours have some code in common. This used to work good but in the latest version of android studio and gradle, I get this error.

SourceSets 'seta' and 'main' use the same file/folder for 'java': .../src/main/java

This is what I have in gradle.build

productFlavors {
    seta {
        packageName "com.test.seta"
        versionCode 4
        versionName "2.0"
    }

    setb {
        packageName "com.test.setb"
        versionCode 2
        versionName "1.6"
    }
}

sourceSets {
    seta {
        java.srcDirs = ['src/main/java', 'src/seta/java']
        res.srcDirs = ['src/main/res', 'src/seta/res']
        assets.srcDirs = ['src/main/assets', 'src/seta/assets']
    }

    setb {
        java.srcDirs = ['src/main/java', 'src/setb/java']
        res.srcDirs = ['src/main/res', 'src/setb/res']
        assets.srcDirs = ['src/main/assets', 'src/setb/assets']
    }

}
Was it helpful?

Solution

In an individual flavor's sourceSet, you don't need to specify the main sourceSet. You can put common code in src/main and it will be picked up without needing to explicitly reference it from other flavors.

I'm not sure how it worked before.

If you remove that, you don't in fact need your sourceSets block at all -- the default behavior is to put common code in src/main and flavor-specific code in src/flavor-name, like how you already have it set up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top