title: Code Path per Flavor in Android Gradle
body: <p>I have 2 buildTypes (debug, release) and 2 productFlavors (product1, product2). I want to define a buildConfigField for each buildType and productFlavors. The buildConfigField is the url the app to download data from the server, and it changes for each productFlavor and buildTypes.</p>
  
  <p>Now, I have:</p>
  
  <pre><code>buildTypes {
      debug {
          debuggable true
      }
      release {
          debuggable false
      }
  }
  productFlavors {
      product1 {
          buildConfigField STRING, "URL_BASE",  '"https://api1.release.com"'
  
      }
      product2 {
          buildConfigField STRING, "URL_BASE", '"https://api2.release.com"'
  
      }
  }
  </code></pre>
  
  <p>But I want something like this:</p>
  
  <pre><code>buildTypes {
      debug {
          debuggable true
      }
      release {
          debuggable false
      }
  }
  productFlavors {
      product1 {
          debug {
              buildConfigField STRING, "URL_BASE",  '"https://api1.debug.com"'
          }
          release {
              buildConfigField STRING, "URL_BASE",  '"https://api1.release.com"'
      }
      product2 {
          debug {
              buildConfigField STRING, "URL_BASE", '"https://api2.debug.com"'
              }
          release {
              buildConfigField STRING, "URL_BASE", '"https://api2.release.com"'
          }
      }
  }
  </code></pre>
  
  <p>How I can achieve this?</p>
  
  <p>Update:</p>
  
  <p>Each URL_BASE has a different pattern so I can't group the URLs. A posible solution is to add the url base of the 2 flavor in the different build types and select the right one in the flavor.</p>
  
  <pre><code>buildTypes {
      debug {
          debuggable true
          buildConfigField STRING, API_VARIANT_PRODUCT1, '"api1.deb.com"'
          buildConfigField STRING, API_VARIANT_PRODUCT2, '"api2.debug.com"'
  
      }
      release {
          debuggable false
          buildConfigField STRING, API_VARIANT_PRODUCT1, '"api1.release.com"'
          buildConfigField STRING, API_VARIANT_PRODUCT2, '"api2.release.com"'
      }
  }
  
  productFlavors {
      product1 {
          buildConfigField STRING, URL_BASE, '"https://" + API_VARIANT_PRODUCT1 + "/v1"'
      }
      product2 {
          buildConfigField STRING, URL_BASE, '"https://" + API_VARIANT_PRODUCT2 + "/v1"'
      }
    }
  }
  </code></pre>
  
  <p>UPDATE 2</p>
  
  <p>If you need to add resources in gradle, like a 'KEY_MAP' the solution is in this <a href="https://gist.github.com/cdsap/19e277b8597b8b39ebc0" rel="noreferrer">page</a>.</p>