Reputation: 780
I have an android project in which i would like to have 2 (potentially more) resources folders (one for each different look), the core functionality is the same but the only difference between them is the colors, themes and values of strings, etc. (which all have the same resource ids, only different content/value) I want to be able to specify the folder i want to compile.
Previously i tried to specify the res.srcDirs inside productFlavours but it didn´t work properly.
Upvotes: 0
Views: 219
Reputation: 150
Read this page, it is very detailed:Using flavours to build multiple editions of an application
But in a nutshell:
Flavours can override your main code and files, so if you have a res folder and want to modify the looks of your application you just have to have a folder above main with the same name as the flavour with the new res folder, with the same name but modified content.
This is your gradle file.
productFlavors {
vanilla {
packageName "com.example.multiflavorapp"
}
strawberry {
packageName "com.example.multiflavorapp.strawberry"
}
}
And this is your directory(dont actualy run it, i can´t post images yet)
app/
|--libs/
|--src/
|--vanilla/
| |--java/
| |--com/example/
| |--Flavor.java
|--strawberry/
| |--java/
| |--com/example/
| |--Flavor.java
|--main/
|--java/
| |--...
|--res/
| |--...
|--AndroidManifest.xml
Example if you have a string app_name="vanilla" referenced from your code and want a different value in another flavour you just modify the value, let´s say app_name="strawberry" and that´s it.
Upvotes: 1
Reputation: 5498
This is exactly what flavors are for. Define a flavor and a source folder with the same name as the flavor. That would be at the same level as "main" and would have "res" in it.
productFlavors {
look1 {}
look2 {}
}
Then your project has folders look1
and look2
at the same level as main, with whatever resources you need in them, for example look1/res/values/strings.xml
Upvotes: 1
Reputation: 2208
Use these dependencies :
android{
.....
sourceSets {
main.res.srcDirs += ['src/main/res', 'src/main/res_apt2']
}
}
Edit: First add the "res_apt2" folder manually inside main/ folder, next add this line
Upvotes: 1