Entry name 'AndroidManifest.xml' collided (Build failed after updating the android gradle plugin to 3.6.0)

Viewed 22931

I have recently updated the Android Studio from 3.5(stable) to 3.6(stable).

Then I saw the plugin update was also available, so I have updated the version of "com.android.tools.build:gradle" from 3.5.0 to 3.6.0 and also updated the gradle version to 5.6.4.

Now the problem starts when I try to build the project; it fails with message Entry name 'AndroidManifest.xml' collided

enter image description here

7 Answers

I found a workaround by adding this to the app's build.gradle:

android {
    packagingOptions {
        exclude 'AndroidManifest.xml'
    }
}

I had this to fix an issue with creating a bundle, due to Facebook's Audience Network, on Android Studio 3.5.

I get a similar error: Entry name 'resources.arsc' collided. Workaround as @Marco Batista said:

android {
    packagingOptions {
        exclude 'resources.arsc'
    }
}

According to the issue this happens when a JAR dependency contains an AndroidManifest.xml file.

For my project, the cause was this old dependency:

androidTestImplementation 'com.google.android:android-test:4.1.1.4' 

Which had a dependency on com.google.android:android:4.1.1.4 which had an AndroidManifest.xml in the JAR.

How I found it

I searched in $HOME\.gradle\caches\modules-2\files-2.1 for all .jar files containing an AndroidManifest.xml (I used Total Commander)

Then I cross referenced the results with the dependencies of my app. To get the dependency tree use the Gradle tool window to run the Tasks/android/androidDependencies gradle task.

There are few methods to resolve this issue.

  1. Revert build.gradle version to 3.5.3

    dependencies {
           // classpath 'com.android.tools.build:gradle:3.6.1'       
              classpath 'com.android.tools.build:gradle:3.5.3'
            }
    
  2. Add packagingOptions under app/build.gradle

    android {
       ...
    
      packagingOptions {
          exclude 'AndroidManifest.xml'
      }
    
     }
    
  3. Under gradle.properties, set useNewApkCreator to false. Adding this flag might cause some apk installation issues.

    android.useNewApkCreator=false
    

Final approach, perform a scan through third-party library. Check for androidx.core:core-ktx plugin. Try to update to 1.2.0 or newer version.

I had the same issue with AndroidManifest.xml files colliding. First, I tried the useNewApkCreator workaround and it worked on the app variant I was working on. But when I switched to another variant, build was still successful but the app refused to install from Android Studio. Also installing the .apk manually gave parsing error on the device.

Finally, I analyzed the .apks from both variants and noticed that the broken .apk had the wrong AndroidManifest.xml in it. Excluding the manifest in packagingOptions worked though.

I tried with

android.useNewApkCreator=false

It was a quick win because I was able to compile, however the AndroidManifest.xml was still wrong. I found out because I needed to apply a hardening process to the APK and the tool was complaining about the AndroidManifest.xml.

This was because, as explained by others, the APK does not have its manifest but one from a dependency. I discovered that by analysing the APK with Android Studio (build/analize APK), that pointed me right to the dependency with the problem. The solution from Marco Batista was useful, but I put that in the dependency's gradle instead of in the app's one.

android {
    packagingOptions {
        exclude 'AndroidManifest.xml'
    } 
}
Related