title: Change apk name with Gradle
body: <p>I have an Android project which uses Gradle for build process. Now I want to add two extra build types staging and production, so my build.gradle contains:</p>
  
  <pre><code>android {
      buildTypes {
          release {
              runProguard false
              proguardFile getDefaultProguardFile('proguard-android.txt')
          }
  
          staging {
              signingConfig signingConfigs.staging
  
              applicationVariants.all { variant -&gt;
                  appendVersionNameVersionCode(variant, defaultConfig)
              }
          }
  
          production {
              signingConfig signingConfigs.production
          }
      }
  }
  </code></pre>
  
  <p>and my appndVersionNameVersionCode looks like:</p>
  
  <pre><code>def appendVersionNameVersionCode(variant, defaultConfig) {
      if(variant.zipAlign) {
          def file = variant.outputFile
          def fileName = file.name.replace(".apk", "-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk")
          variant.outputFile = new File(file.parent, fileName)
      }
  
      def file = variant.packageApplication.outputFile
      def fileName = file.name.replace(".apk", "-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk")
      variant.packageApplication.outputFile = new File(file.parent, fileName)
  }
  </code></pre>
  
  <p>If I execute task <em>assembleStaging</em> then I get proper name of my apk, but when I execute <em>assembleProduction</em> then I get changed names of my apk (like in staging case). For example:</p>
  
  <pre><code>MyApp-defaultFlavor-production-9.9.9-999.apk
  MyApp-defaultFlavor-production-9.9.9-999.apk
  </code></pre>
  
  <p>It looks like in production build type is executed <em>appendVersionNameVersionCode</em>. How can I avoid it?</p>