title: Replacing a string in AndroidManifest.xml for a buildvariant doesn't work for Gradle Android Plugin Version > 0.5.4
body: <p>Just a few weeks ago I had the following question: <a href="https://stackoverflow.com/questions/17465353/how-to-replace-a-string-for-a-buildvariant-with-gradle-in-android-studio">How to replace a string for a buildvariant with gradle?</a></p>
  
  <p>I also answered the question on my own. </p>
  
  <p>Everything works fine until now: I just realized that my copy task doesn't work anymore. I spent a few hours on the problem until I realized that it depends on the Gradle Android Plugin Version: Everything until 0.5.4 works fine. For upper versions I won't get into my copy task.</p>
  
  <p>Here is the console output:</p>
  
  <pre><code>// gradle android plugin version: 0.5.6 and 0.5.5 --&gt; copy tas doesn't work
  :etscanner:prepareFlavor1Flavor1ReviewDependencies
  :etscanner:compileFlavor1Flavor1ReviewAidl
  :etscanner:generateFlavor1Flavor1ReviewBuildConfig
  :etscanner:mergeFlavor1Flavor1ReviewAssets
  :etscanner:compileFlavor1Flavor1ReviewRenderscript
  :etscanner:mergeFlavor1Flavor1ReviewResources
  :etscanner:processFlavor1Flavor1ReviewManifest
  :etscanner:processFlavor1Flavor1ReviewResources
  :etscanner:compileFlavor1Flavor1ReviewNote: Some input files use or override a d
  eprecated API.
  Note: Recompile with -Xlint:deprecation for details.
  Note: &lt;path&gt;.DetailAdapter
  .java uses unchecked or unsafe operations.
  Note: Recompile with -Xlint:unchecked for details.
  
  :etscanner:dexFlavor1Flavor1Review
  :etscanner:processFlavor1Flavor1ReviewJavaRes UP-TO-DATE
  :etscanner:validateFlavor1Flavor1Signing
  :etscanner:packageFlavor1Flavor1Review
  :etscanner:zipalignFlavor1Flavor1Review
  
  // gradle android plugin version: 0.5.4 --&gt; copy task work
  :etscanner:prepareFlavor1Flavor1ReviewDependencies
  :etscanner:compileFlavor1Flavor1ReviewAidl
  :etscanner:generateFlavor1Flavor1ReviewBuildConfig
  :etscanner:mergeFlavor1Flavor1ReviewAssets
  :etscanner:compileFlavor1Flavor1ReviewRenderscript
  :etscanner:mergeFlavor1Flavor1ReviewResources
  :etscanner:processFlavor1Flavor1ReviewManifest
  ...hey you are in the copy task!
  :etscanner:processFlavor1Flavor1ReviewResources
  :etscanner:compileFlavor1Flavor1ReviewNote: Some input files use or override a d
  eprecated API.
  Note: Recompile with -Xlint:deprecation for details.
  Note: &lt;path&gt;DetailAdapter
  .java uses unchecked or unsafe operations.
  Note: Recompile with -Xlint:unchecked for details.
  
  :etscanner:dexFlavor1Flavor1Review
  :etscanner:processFlavor1Flavor1ReviewJavaRes UP-TO-DATE
  :etscanner:validateFlavor1Flavor1Signing
  :etscanner:packageFlavor1Flavor1Review
  :etscanner:zipalignFlavor1Flavor1Review
  :etscanner:assembleFlavor1Flavor1Review
  </code></pre>
  
  <p>It's really a strange thing...
  Has anyone an idea how to fix this?</p>
  
  <p><strong>UPDATE 1 2013-08-23</strong></p>
  
  <p>My build.gradle file:</p>
  
  <pre><code>buildscript {
      repositories {
          // maven central repo doesn't work with gradle android plugin version 0.5.+
          // error message is describe in this post:
          // https://plus.google.com/117954254390243608387/posts/RVBjoDMkLV5
          //mavenCentral()
          maven {
              url 'http://nexus/content/groups/public/'
          }
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:0.5.4'
          // copy task doesn't work for following versions:
          //classpath 'com.android.tools.build:gradle:0.5.5'
          //classpath 'com.android.tools.build:gradle:0.5.6'
          //classpath 'com.android.tools.build:gradle:0.5.+'
      }
  }
  
  apply plugin: 'android'
  
  dependencies {
      compile 'com.android.support:support-v4:13.0.+' // support lib
      //compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
      compile project(':libraries:actionbarsherlock')
      compile project(':libraries:google-play-services_lib')
  }
  
  android {
      compileSdkVersion 17
      buildToolsVersion "17.0.0"
  
      defaultConfig {
          minSdkVersion 8
          targetSdkVersion 17
          versionName = "2.3"
          versionCode = 4
      }
  
      // SIGN CONFIGS
      signingConfigs {
          flavor1 {
              storeFile file("keystore/myKeystore.keystore")
              storePassword = "store_password"
              keyAlias = "alias"
              keyPassword = "key_password"
          }
          flavor2 {
              storeFile file("keystore/myKeystore.keystore")
              storePassword = "store_password"
              keyAlias = "alias"
              keyPassword = "key_password"
          }
          debug {
              storeFile file("keystore/debug.keystore")
              storePassword = "android"
              keyAlias = "androiddebugkey"
              keyPassword = "android"
          }
  
      }
  
      // FLAVORS
      productFlavors {
          flavor1 {
              packageName 'myPackageName'
              signingConfig signingConfigs.flavor1
          }
          flavor2 {
              packageName 'myPackageName'
              signingConfig signingConfigs.flavor2
          }
      }
  
      // BUILDTYPES
      buildTypes {
          falvor1Review {
              versionNameSuffix = versionNameSuffixOfReviewVersion
              signingConfig signingConfigs.flavor1
          }
          flavor2Review {
              versionNameSuffix = versionNameSuffixOfReviewVersion
              signingConfig signingConfigs.flavor2
          }
  
          debug {
              packageNameSuffix ".debug"
              versionNameSuffix = versionNameSuffixOfReviewVersion
              signingConfig signingConfigs.debug
          }
      }
  
      // Override Data in Manifest
      android.applicationVariants.each { variant -&gt;
          variant.processManifest.doLast {
              copy {
                  // *** SET COPY PATHS ***
                  try {
                      from("${buildDir}/manifests") {
                          //println "from: ${buildDir}/manifests"
                          include "${variant.dirName}/AndroidManifest.xml"
                          //println "included: ${variant.dirName}/AndroidManifest.xml"
                      }
                  } catch (e) {
                      println "error: " + e
                  }
  
                  into("${buildDir}/manifests/${variant.name}")
                  //println "into (neues Manifest): ${buildDir}/manifests/${variant.name}"
  
                  // *** DEFINE VARS ***
                  def brandVersion = variant.buildType.name
                  def brandVersionString = brandVersion.toString()
                  def appName = "empty"
  
                  // *** SET APP NAME ***
                  if (brandVersionString.contains("flavor1")) {
                      appName = "my app name for flavor 1"
                  } else if (brandVersionString.contains("flavor2")) {
                      appName = "my app name for flavor 2"
                  }
  
                  println "...hey you are in the copy task"
                  // *** REPLACE LINES IN MANIFEST ***
                  // --- add appName
                  filter {
                      String line -&gt;
                          line.replaceAll("&lt;application android:allowBackup=\"true\" android:icon=\"@drawable/ic_launcher\" android:label=\"todo\" android:theme=\"@style/AppTheme\"&gt;",
                                  "&lt;application android:allowBackup=\"true\" android:icon=\"@drawable/ic_launcher\" android:label=\"" + appName + "\" android:theme=\"@style/AppTheme\"&gt;");
                  }
              }
          }
  
          // *** SET PATH TO NEW MANIFEST *** 
          variant.processResources.manifestFile = file("${buildDir}/manifests/${variant.name}/${variant.dirName}/AndroidManifest.xml")
          //println "newManifest: ${buildDir}/manifests/${variant.name}/${variant.dirName}/AndroidManifest.xml"
      }
  }
  </code></pre>
  
  <p><strong>UPDATE 2 2013-08-23</strong></p>
  
  <p>Yesterday I had another strange behaviour of AS 0.2.5, it made some really strange builds: 
  As you see in my filter my previous appName in the Manifest is "todo":</p>
  
  <pre><code>&lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="todo"
      android:theme="@style/AppTheme"&gt;
  </code></pre>
  
  <p>When I made the build then the appName in the app was the right one. But in the Application Launcher and in Settings/Apps there was shown "todo" as appName.</p>
  
  <p>After building the project in AS 0.2.0 everything works fine.</p>