Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two flavours with different resources inheriting layout from one base flavour

I have my android application split into four different build flavours. Each of these flavours have a portion of unique java and xml files, and a portion of shared files under main. For the sake of clarity, let's call these Cucumber, Tomato, Onion and Pepper. These flavours have unique layouts, drawables, strings, colours, java files, etc.

My requirement is now that I need to split my Pepper flavour into two sub-flavours; Red-Pepper and Green-Pepper. The layouts for these two flavours should be identical - the only different is that the two flavours must use different drawable and string resources. I don't want to have duplicate layout files in both the red and green flavours for obvious reasons.

How can this be achieved in gradle?

like image 368
Mike Baxter Avatar asked Sep 29 '15 11:09

Mike Baxter


1 Answers

You can define multiple resource folders.
In this way you can use common folders for 2 flavors (in you redPepper and greenPepper).
For example something like this:

android {
     ...
     sourceSets {
            main {
                //....
                res.srcDirs = ['/src/main/res']

            }
            redPepper {
                 res.srcDirs = ['/src/flavorRed/res', '/src/commonPepper/res']
            }
            greenPepper {
                 res.srcDirs = ['/src/flavorGreen/res', '/src/commonPepper/res']
            }     
            //.....other flavors   
     }
}
like image 152
Gabriele Mariotti Avatar answered Nov 15 '22 17:11

Gabriele Mariotti