title: How to define and use a constant in Gradle build script (Android)?
body: <p>I'm working on an Android application with Gradle as its build system.</p>
  
  <p>My objective is to use a value (a package name) as an <code>applicationId</code>:</p>
  
  <pre><code>productFlavors {
     orange {
        applicationId "com.fruits.android.orange"
        // ...
  </code></pre>
  
  <p>But also to expose it via <code>BuildConfig</code> so that Java code has access to it. </p>
  
  <p>This access has to be from outside the flavor (namely, free version of the app needs to know the package name of the paid version so that it can prompt user for an upgrade in Play store).</p>
  
  <p>So I'd like to do something like that:</p>
  
  <pre><code>productFlavors {
     orange {
        applicationId orangeProPackage
        // ...
  
  
  buildConfigField 'String', 'ORANGE_PRO_PACKAGE', "$orangeProPackage" // ?
  </code></pre>
  
  <p>Only I'm not sure how to define <code>orangeProPackage</code> so that it's visible in the entire build.gradle and doesn't break the script.</p>
  
  <p>Since there's a few different flavors, it would be best if I could somehow group all these constants like that (I guess?):</p>
  
  <pre><code>def proPackages = [
          orange: "..."
          apple: "..."
          banana: "..."
  ]
  </code></pre>
  
  <p>and then refer to them in a clean and descriptive manner like <code>proPackages.orange</code> etc. </p>
  
  <p>The question is, how to accomplish that?</p>
  
  <p>This is not a duplicate of <a href="https://stackoverflow.com/questions/17197636/is-it-possible-to-declare-a-variable-in-gradle-usable-in-java">Is it possible to declare a variable in Gradle usable in Java?</a></p>
  
  <p>I've seen that question (and a few others). I know how to declare buildConfigFields, I already have plenty. My question is about <em>reusing</em> the same value as a <code>buildConfigField</code> <em>and</em> <code>applicationId</code>.</p>