I am using product flavors and able to create different strings.xml for different flavors but when I try to create raw folder under res for different flavors, I am unable to access files under raw folder for that flavor, instead it is referring to main's raw folder file for every flavor.
Use case - I need json files (files saved with same name under different flavor folders) with different content for different flavors.
I want to access these files using R.raw.xyz
project structure:-
app
--src
--dev
--res
--values/strings.xml
--raw/xyz.json
--production
--res
--values/strings.xml
--raw/xyz.json
--main
--res
--values/strings.xml
--raw/xyz.json
You should configure sourceSets (here you have the full manual).
By default, Android Studio creates the main/ source set and directories for everything you want to share between all your build variants. However, you can create new source sets to control exactly what files Gradle compiles and packages for specific build types, product flavors (and combinations of product flavors when using flavor dimensions), and build variants.
This is your case, and finally in the project structure it somehow
should look like below:
android {
...
sourceSets {
main {
java.srcDirs = ['other/java']
res.srcDirs = ['src/all/res']
manifest.srcFile 'other/AndroidManifest.xml'
...
}
production {
res.srcDirs = ['src/production/res']
...
}
dev {
res.srcDirs = ['src/dev/res']
...
}
}
}