title: Gradle 7 on Android: add BuildConfigField with new variant api from AGP 7
body: <p>I used to add some attributes to BuildConfig on my Android project depending on the build variant and other logic.</p>
  <p>Using Gradle 7 with AGP 7.0.1 I cannot figure out how to add a BuildConfig field in the onVariants closure in my groovy gradle file:</p>
  <pre><code>androidComponents {
      onVariants(selector().withBuildType(&quot;release&quot;), {
        ...here...
      })
  }
  </code></pre>
  <p>I tried several things like:</p>
  <pre><code>it.buildConfigFields.put(&quot;MY_KEY&quot;, BuildConfigField(&quot;String&quot;, &quot;\&quot;$someSecretValue\&quot;&quot;, null))
  </code></pre>
  <p>or</p>
  <pre><code>it.addBuildConfigField(&quot;MY_KEY&quot;, &quot;\&quot;$someSecretValue\&quot;&quot;, &quot;key description&quot;)
  </code></pre>
  <p>which is only available for build files in kotlin.</p>
  <p>How can I do this using AGP 7's Variant Api?</p>
  <p>This is my original code I want to migrate:</p>
  <pre><code>android.applicationVariants
     .matching { v -&gt; ['release'].contains(v.name) }
     .all { variant -&gt;
       variant.buildConfigField('String', 'MY_KEY', '&quot;$someSecretValue&quot;')
     }
  </code></pre>
  <p>Any suggestion is appreciated!</p>