I assume you're asking where you put flavor-specific reources; if you're asking where to make changes to the main sources and resources, that's in the directory structure you mapped out under sourceSets.main
.
You can add this bit of script to the top level of your build.gradle file (e.g. after the android
block) to print out the directories where it will look for resources:
println "main: " + android.sourceSets.main.res.srcDirs
android.applicationVariants.all { variant ->
println variant.name + ": " + android.sourceSets[variant.name].res.srcDirs
}
android.productFlavors.all { flavor ->
println flavor.name + ": " + android.sourceSets[flavor.name].res.srcDirs
}
android.buildTypes.all { buildType ->
println buildType.name + ": " + android.sourceSets[buildType.name].res.srcDirs
}
This outputs the flavor-specific resource directories, and also the build variant (flavor + build type directories).
When I run them on your build file, I get:
main: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/res]
app1: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/src/app1/res]
app2: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/src/app2/res]
debug: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/build-types/debug/res]
release: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/build-types/release/res]
app1Debug: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/src/app1Debug/res]
app1Release: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/src/app1Release/res]
app2Debug: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/src/app2Debug/res]
app2Release: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/src/app2Release/res]
The directory for main is expected -- that's what's explicitly set in sourceSets.main
. The debug and release types we see remapped to the build-types directory as per the statements at the end of your sourceSets
block. For the app1 and app2 flavors, it's looking in src/app1 and src/app2, which is probably not what you want. I'd recommend moving the entire root directory for your flavors, similar to how you do for the build types. I'd change that block at the end to:
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
app1.setRoot('product-flavors/app1')
app2.setRoot('product-flavors/app2')
As for the variants, app1Debug et al, you maybe don't have to worry about them, unless you're doing something so specific that you really need to override on that detailed a basis. At any rate, now when I run and look at my diagnostic output, I see:
main: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/res]
app1: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/product-flavors/app1/res]
app2: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/product-flavors/app2/res]
debug: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/build-types/debug/res]
release: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/build-types/release/res]
app1Debug: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/src/app1Debug/res]
app1Release: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/src/app1Release/res]
app2Debug: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/src/app2Debug/res]
app2Release: [/Users/sbarta/AndroidStudioProjects/AS_Eclipse/app/src/app2Release/res]