title: How to set variable according to gradle flavors
body: <p>I want to pass a variable <code>test</code> that I set differently per flavor as a define to the NDK. But for some reason he always passes the value of the last flavor.</p>
  
  <p><strong><em>Here is the build.gradle:</em></strong></p>
  
  <pre><code>apply plugin: 'com.android.library'
  
  def test
  
  android {
      compileSdkVersion 23
      buildToolsVersion "23.0.2"
      defaultPublishConfig "flavorARelease"
      publishNonDefault true
  
      defaultConfig {
          minSdkVersion 15
          targetSdkVersion 17
  
          ndk {
              moduleName "test"
              ldLibs "log"
          }
      }
  
      productFlavors {    
          flavorA {
              test = 1
          }
  
          flavorB {
              test = 2
          }    
      }
  
      buildTypes {    
          debug {
              ndk {
                  if (cFlags == null) { cFlags = "" }
                  cFlags = cFlags + " -DLOGGING=1 -DTEST="+test+" "
              }
              minifyEnabled false
          }
          release {
              ndk {
                  if (cFlags == null) { cFlags = "" }
                  cFlags = cFlags + " -DLOGGING=0 -DTEST="+test+" "
              }
              minifyEnabled true
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      testCompile 'junit:junit:4.12'
      compile 'com.android.support:appcompat-v7:23.1.1'
  }
  </code></pre>
  
  <p>And here are the CFLAG lines from the generated Android.mk</p>
  
  <p><strong><em>build/intermediates/ndk/flavorA/debug/Android.mk:</em></strong></p>
  
  <pre><code>LOCAL_CFLAGS :=  -DLOGGING=1 -DTEST=2
  </code></pre>
  
  <p>I expected <code>-DTEST=1</code> here</p>
  
  <p><strong><em>build/intermediates/ndk/flavorB/debug/Android.mk:</em></strong></p>
  
  <pre><code>LOCAL_CFLAGS :=  -DLOGGING=1 -DTEST=2
  </code></pre>
  
  <p>So where is my mistake? Or how can I achieve my goal? Please also consider that the real problem is more complex and I want to make those defines in the "buildTypes" segment if possible.</p>