0

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']
    }

}
Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
Elyess Abouda
  • 659
  • 12
  • 20

1 Answers1

2

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.

Scott Barta
  • 79,344
  • 24
  • 180
  • 163
  • does this also apply for library projects? I'm having an issue where when defining a flavor for a library project causes the main application not to pick up resources from the library project. I'm using the "canonical" directory structure. – andreimarinescu Jan 16 '15 at 13:55
  • @andreimarinescu, I'd recommend starting a new question with more details on what you're doing. – Scott Barta Jan 16 '15 at 17:18
  • 1
    Hi Scott, I was missing the defaultPublishConfig "flavor" and publishNonDefault true statements in my library gradle file. Thanks anyway! – andreimarinescu Jan 21 '15 at 10:25
  • @ScottBarta Is it possible to have android project without application module folder in android studio? Here is my SO question - http://stackoverflow.com/questions/33755292/can-we-have-project-without-app-folder-in-android-studio-with-everything-java-r – Scorpion Nov 17 '15 at 13:26
  • @ScottBarta I have removed the app folder and created folder structure like Eclipse in android studio but i stuck on building gradle as i am not getting Sync Gradle option now.. – Scorpion Nov 17 '15 at 13:27