title: productFlavor variables in Android Studio / Gradle
body: <p>I have an android application that has the following product flavors:</p>
  
  <pre><code>productFlavors {
      local {
  
      }
  
      development {
  
  
      }
  
      production {
  
      }
  }
  </code></pre>
  
  <p>then have the following at the bottom of my <code>build.grade</code>:</p>
  
  <pre><code>File crashlyticsProperties = new File("${project.projectDir.absolutePath}/fabric.properties")
  android.applicationVariants.all { variant -&gt;
      def variantSuffix = variant.name.capitalize()
      def generateResourcesTask = project.tasks.getByName("fabricGenerateResources${variantSuffix}")
      def generatePropertiesTask = task("fabricGenerateProperties${variantSuffix}") &lt;&lt; {
          Properties properties = new Properties()
          properties.put("apiSecret", WHAT_GOES_HERE)
          properties.put("apiKey", WHAT_GOES_HERE)
          PropertiesUtils.injectPropertyInFile(crashlyticsProperties, properties, "")
      }
      generateResourcesTask.dependsOn generatePropertiesTask
  }
  </code></pre>
  
  <p>I'm trying to set the <code>api secret/key</code> for <code>crashlytics</code> but I need to be able to set these depending on what product flavor I'm building. </p>
  
  <pre><code>properties.put("apiSecret", WHAT_GOES_HERE)
  properties.put("apiKey", WHAT_GOES_HERE)
  </code></pre>
  
  <p>How can I set/get these variables?</p>
  
  <h3>Update #1</h3>
  
  <p>I've added the following to my <code>build.gradle</code></p>
  
  <pre><code>productFlavors {
      local {
          buildConfigField "String", "CRASHLYTICS_API_SECRET", "1234"
          buildConfigField "String", "CRASHLYTICS_API_KEY", "1234"
      }
  
      development {
          buildConfigField "String", "CRASHLYTICS_API_SECRET", "1234"
          buildConfigField "String", "CRASHLYTICS_API_KEY", "1234"
      }
  
      production {
          buildConfigField "String", "CRASHLYTICS_API_SECRET", "1234"
          buildConfigField "String", "CRASHLYTICS_API_KEY", "1234"
      }
  }
  </code></pre>
  
  <p>Then at the bottom of the <code>build.gradle</code> file I have:</p>
  
  <pre><code>File crashlyticsProperties = new File("${project.projectDir.absolutePath}/fabric.properties")
  android.applicationVariants.all { variant -&gt;
      def variantSuffix = variant.name.capitalize()
      def generateResourcesTask = project.tasks.getByName("fabricGenerateResources${variantSuffix}")
      def generatePropertiesTask = task("fabricGenerateProperties${variantSuffix}") &lt;&lt; {
          Properties properties = new Properties()
          println "...copying apiSecret for ${variant.name}"
          properties.put("apiSecret", BuildConfig.CRASHLYTICS_API_SECRET)
          println "...copying apiKey for ${variant.name}"
          properties.put("apiKey", BuildConfig.CRASHLYTICS_API_KEY)
          PropertiesUtils.injectPropertyInFile(crashlyticsProperties, properties, "")
      }
      generateResourcesTask.dependsOn generatePropertiesTask
  }
  </code></pre>
  
  <p>This however does not compile and gives me:</p>
  
  <blockquote>
    <p>Error:(334, 1) Execution failed for task ':app:fabricGeneratePropertiesDevelopmentDebug'.
    Could not find property 'BuildConfig' on task ':app:fabricGeneratePropertiesDevelopmentDebug'.</p>
  </blockquote>