title: How to use variable in gradle files?
body: <p>I'd like to declare an API version my test application uses to build it and also display it in the application.</p>
  
  <p>So I declared the version like that in the project's build.gradle:</p>
  
  <pre><code>buildscript {
      ext {
          ...
          api_version = '0.2.9'
      }
      ...
  }
  </code></pre>
  
  <p>Then in my app's build gradle, I use it:</p>
  
  <pre><code>android {
      ....
      buildTypes {
          release {
              ...
              buildConfigField "String", "api_version", "$api_version"
          }
          debug {
              ...
              buildConfigField "String", "api_version", "$api_version"
          }
      }
  }
  
  dependencies {
      ....    
      implementation "com.example.service:my_api:$api_version"
  }
  </code></pre>
  
  <p>And finally, I use it in my app:</p>
  
  <pre><code>    supportActionBar?.title = """${getString(R.string.app_name)} $VERSION_NAME API:${BuildConfig.api_version}"""
  </code></pre>
  
  <p>But on build I get the following error in the generated <code>BuildConfig.java</code> file:</p>
  
  <pre><code>public final class BuildConfig {
  
    // Fields from build type: debug
    public static final String api_version = 0.2.9;
  }
  </code></pre>
  
  <p>The error is</p>
  
  <pre><code>......\BuildConfig.java
  Error:(14, 54) error: ';' expected
  </code></pre>
  
  <p>I suppose BuildConfig.java should contain:</p>
  
  <pre><code>public static final String api_version = "0.2.9";
  </code></pre>
  
  <p>But I don't understand how to write it.</p>