33

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

auspicious99
  • 3,902
  • 1
  • 44
  • 58
Rikin Prajapati
  • 1,913
  • 2
  • 16
  • 23
  • can you add an error image for better understanding? – Praful Korat Feb 26 '20 at 09:13
  • 1
    Caused by: java.lang.IllegalStateException: Entry name 'AndroidManifest.xml' collided at com.android.zipflinger.ZipArchive.validateName(ZipArchive.java:302) at com.android.zipflinger.ZipArchive.writeSource(ZipArchive.java:246) at com.android.zipflinger.ZipArchive.add(ZipArchive.java:126) at com.android.signflinger.SignedApk.add(SignedApk.java:135) ... at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131) ... 3 more – T. Aslam Feb 26 '20 at 09:43
  • I got the same issue. I run "./gradlew assembleDebug --debug" and got this error log "Task :app:packageDebug FAILED". It could be something wrong with the new packaging tool. Build successful after disabled it by adding "android.useNewApkCreator=false" in gradle.properties file – Tan Tran Feb 26 '20 at 14:02
  • same here.. after updating android studio to 3.6 and updating all available plugin then this problem show up when try to Run app and Rebuild Project. **Entry name 'AndroidManifest.xml' collided** don't know what to do. – Espada Feb 26 '20 at 14:18
  • Please have a look to similar answer https://stackoverflow.com/a/60469132/10646780 – Jatin Sahgal Mar 02 '20 at 11:03

7 Answers7

79

This is caused by Android Gradle plugin 3.6

Revert to using the old packaging tool by including the following in your gradle.properties file will fix this issue

android.useNewApkCreator=false

More info please check the release note: https://developer.android.com/studio/releases/gradle-plugin#zipflinger

ND1010_
  • 3,743
  • 24
  • 41
xfx
  • 814
  • 7
  • 3
  • 2
    where should you add this exactly? – Rami Ammoun Mar 20 '20 at 06:44
  • 3
    gradle.properties – sweggersen Mar 31 '20 at 20:41
  • 1
    This is a useful answer. It could be even better if there was an explanation of what the new tool isn't liking. – Jameson Apr 16 '20 at 05:18
  • I was going all ninja on this issue by cleaning my project. Invalidate and Restart for a million times. Thank this helped Also, my error was: Entry name 'kotlin/collections/MapWithDefault.kotlin_metadata' collided – Karan Sharma Apr 23 '20 at 17:05
  • 2
    Using this, i get the error on installing that the APK cannot be parsed on the device. – Thommy May 05 '20 at 13:37
  • 1
    This indeed worked. But why this property should be applied to my laptop but for others project is working fine even without this property? – AndroidEngineX Aug 19 '20 at 06:23
  • I just got this error for bugsnag: `Entry name 'assets/include/bugsnag.h' collided` only when generating an APK from the `Build > Generate Signed Bundle / APK` option. Adding this to gradle.properties fixed the issue. Thanks. – gMale Apr 09 '21 at 15:05
  • not sure why but `useNewApkCreator` this seems to cause the IDE to build the wrong variant! Still investigating but it seems to always build the last variant that I used for `Build > Generate Signed Bundle / APK` even though I'm pressing the 'play' button after changing variants and cleaning! – gMale Apr 09 '21 at 18:49
21

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.

Marco Batista
  • 1,410
  • 1
  • 20
  • 38
6

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.

keccs
  • 153
  • 1
  • 6
  • Good idea. For me it was FirebaseCrashlytics – Thommy Jun 18 '20 at 15:34
  • To use such 'com.google.android` libs correctly you should use `compileOnly` instead like `androidTestCompileOnly 'com.google.android:android-test:4.1.1.4'` – DropDrage May 07 '23 at 15:59
5

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

android {
    packagingOptions {
        exclude 'resources.arsc'
    }
}
android_su
  • 1,637
  • 4
  • 21
  • 30
4

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.

RayChongJH
  • 401
  • 1
  • 5
  • 6
1

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.

JulleR
  • 11
  • 2
0

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'
    } 
}