title: Android Gradle Read App Name from strings.xml
body: <p>I am trying to rename my APK files for each build variant to include the application name, versionName, versionCode and build number when present. So far I have everything working except the application name.</p>
  
  <p>I want to use the same value that the <code>AndroidManifest.xml</code> file uses for android:label. This comes from a string resource <code>@string/app_name</code>. I have seen the ability to replace the resource values by using:</p>
  
  <pre><code>resValue "string", "app_name", "Some new value"
  </code></pre>
  
  <p>But I would just like to read this value and use it to name my APK file.</p>
  
  <pre><code>android.applicationVariants.all { variant -&gt;
      variant.outputs.each { output -&gt;
          renameApk(variant, output)
      }
  }
  
  def renameApk(variant, output) {
      def apkPath = output.outputFile.parent
      def baseName = project.archivesBaseName
  
      baseName += "-${variant.buildType.name}"
  
      // add version name and version code
      baseName += "-v${variant.mergedFlavor.versionName}-${variant.mergedFlavor.versionCode}"
  
      // if built on jenkins ci, add jenkins build number:
      def buildNumber = System.getenv('BUILD_NUMBER')
      if (buildNumber &amp;&amp; buildNumber.size() &gt; 0) {
          baseName += "-b${buildNumber}"
      }
  
      // if the variant will not be zipAligned, specify that
      if (!output.zipAlign) {
          baseName += '-unaligned'
      }
  
      // set the output file
      output.outputFile = new File(apkPath, "${baseName}.apk");
  }
  </code></pre>