title: How to use multiple res.srcDirs and override some resources with gradle
body: <p>I want to build different versions of my app based on different <em>productFlavors</em>, but need some degree of flexibility that I can't achieve yet. </p>
  
  <p>This is my folder structure:</p>
  
  <pre><code>+src
    +main
      +java
      +res
    +base
      +java
      +res
    +custom1
      +java
      +res
    +custom2
      +res
  </code></pre>
  
  <p>The common code is on <strong>main</strong> (a service) and the base ui is on <strong>base</strong> (the activity). Then a custom version of the app that defines a new ui is on <strong>custom1</strong> (new activity). This is running fine. But I need another version of the app (<strong>custom2</strong>) that uses the <strong>base</strong> ui, but changing some of the res (icons, strings or colors).</p>
  
  <p>What I'm trying in my build.gradle file is:</p>
  
  <pre><code>android{
      ...
    productFlavors {
      base {
        ...
      }
      custom1 {
        ...
      }
      custom2 {
        ...
      }
    }
  
    sourceSets{
      custom2{
        java.srcDirs = ['src/base/java']
        res.srcDirs = ['src/custom2/res', 'src/base/res']
      }
    }
  }
  </code></pre>
  
  <p>To specify that <strong>custom2</strong> will use the source code and resources of <strong>base</strong> and the resources of <strong>custom2</strong>.</p>
  
  <p>The problem is that I get a:</p>
  
  <pre><code>Error: Duplicate resources: &lt;project_path&gt;/src/base/res/values-es/strings.xml:string-en/app_name, &lt;project_path&gt;/src/custom2/res/values-es/strings.xml:string-en/app_name
  </code></pre>
  
  <p>Because <code>app_name</code> is defined both on <strong>base</strong> and on <strong>custom2</strong>, but my goal is to override the definition of resources in <strong>base</strong> with the ones of <strong>custom2</strong>.</p>
  
  <p>I know that <code>app_name</code> will be overriden in <strong>main</strong> if I don't specify anything in <code>res.srcDirs</code> for <strong>custom2</strong>, but then all the resources from <strong>base</strong> will be unavailable.</p>
  
  <p>Is the approach correct? or I'm abusing of the flexibility that Gradle offers? or there is a way to do what I'm trying to do?</p>
  
  <p>Thanks in advance!</p>