Edit AndroidManifest attributes

Hi :slight_smile: I would like to add tools:replace="allowBackup, label" attribute to my AndroidManifest to avoid this kind of errors with gradle libraries:

/Users/jesusmartinez/FuseProjects/Fuse.Conekta/Example/build/Android/Preview/app/src/main/AndroidManifest.xml:20:18-45 Error:
	Attribute application@allowBackup value=(false) from AndroidManifest.xml:20:18-45
	is also present at [io.conekta:conektasdk:2.1] AndroidManifest.xml:12:9-35 value=(true).
	Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml:17:5-64:19 to override.
/Users/jesusmartinez/FuseProjects/Fuse.Conekta/Example/build/Android/Preview/app/src/main/AndroidManifest.xml:17:18-51 Error:
	Attribute application@label value=(Example (preview)) from AndroidManifest.xml:17:18-51
	is also present at [io.conekta:conektasdk:2.1] AndroidManifest.xml:13:9-41 value=(@string/app_name).
	Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:17:5-64:19 to override.

This seems not to work
[Require("AndroidManifest.RootElement", "<application tools:replace=\"android:label\"/>")]

Any idea how to solve it?


currently there is no way to add arbitrary attributes to the <application /> node in AndroidManifest.xml. You will need to add that manually, and then use the build.sh/build.bat script to rebuild the APK after changing the manifest.

I had the same problem, and while the manual solution definitely works, it’s very annoying to have to update the file every build. You can definitely automate this type of thing with gradle. I’m not a gradle expert, and the below solution might be “hacky”, but it’s worked for me so far.

Essentially, what you want to do is write a gradle task that will modify your manifest file, and make sure this task runs before the manifest is needed. What I did was create a uxl file and make sure to include it in my unoproj. The contents of the uxl file would look something like below.

NOTE: I haven’t figured out how to get the manifest file path based on build variant/flavor from gradle, so I’ve just been using the full absolute path to my manifest.

<Extensions Backend="CPlusPlus">
  <Require Condition="Android" Gradle.BuildFile.End>
      // define the task
      task updateManifest(type: UpdateManifestTask)

      // implement the task
      class UpdateManifestTask extends DefaultTask {
        def update() {

          // find the manifest and get the contents
          // TODO: use gradle to find manifest path based on variant/flavor
          def manifestPath = "C:/Dev/Fuse/GameTime/build/Android/Debug/app/src/main/AndroidManifest.xml"
          def manifestFile = new File(manifestPath)
          def content = manifestFile.getText()

          // update content, in our case, find and replace some string
          def updatedContent = content.replaceAll("android:allowBackup=\"false\"", "android:allowBackup=\"true\"")

      // make processDebugManifest task depend on our new task to ensure the manifest is updated when it's needed
      afterEvaluate {
        processDebugManifest.dependsOn updateManifest

Thank you very much for sharing Mitchell (: That solution looks great! I ended replacing the entire AndroidManifest using UXL.
Here is the result: https://github.com/jesusmartinoza/Fuse.Conekta/blob/master/src/android_support.uxl