Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Android "Duplicate class foo found in module bar" error

I have android module named A. I added dependency to another module B like so: implementation project(':B'). While the module A builds without an issue, when I try to build (and run) integration tests, I get

Duplicate class org.xmlpull.v1.XmlPullParser found in modules kxml2-2.3.0.jar (net.sf.kxml:kxml2:2.3.0) and xpp3-1.1.3.3.jar (xpp3:xpp3:1.1.3.3)
Duplicate class org.xmlpull.v1.XmlPullParserException found in modules kxml2-2.3.0.jar (net.sf.kxml:kxml2:2.3.0) and xpp3-1.1.3.3.jar (xpp3:xpp3:1.1.3.3)
Duplicate class org.xmlpull.v1.XmlPullParserFactory found in modules kxml2-2.3.0.jar (net.sf.kxml:kxml2:2.3.0) and xpp3-1.1.3.3.jar (xpp3:xpp3:1.1.3.3)
Duplicate class org.xmlpull.v1.XmlSerializer found in modules kxml2-2.3.0.jar (net.sf.kxml:kxml2:2.3.0) and xpp3-1.1.3.3.jar (xpp3:xpp3:1.1.3.3)

I tried to exclude org.xmlpull.kxml by changing my import statement to

    implementation (project(':B')) {
        exclude group: 'org.xmlpull.v1'
    }

but the problem still exists. I have run out of ideas. Can anyone help?

like image 476
Comfy Cat Avatar asked Sep 09 '19 08:09

Comfy Cat


People also ask

How to fix duplicate classes exception in Gradle?

Show activity on this post. Sometimes duplicate classes exception means that one of your dependencies uses implicitly the older or newer (with +) version of some library you also use in your project, To resolve this issue you may add such block of code (put your library version after 'force') to your build.gradle file (Module:app):

How to fix Android Studio won’t open Gradle files?

For this, you have to connect your PC to the internet and you have to open your Android studio. After opening your project click on the Sync Project with Gradle files option. This will automatically download the new Gradle files and will fix the issue which is caused by the Gradle files.

How to sync Android Studio project with Gradle files?

After deleting this folder we have to reopen our Android studio and then navigate to the Files option in the top bar and then click on Sync Project with Gradle Files to sync your project it will automatically download the new Gradle files which are required for your project. You can get to see this option on the below screenshot.

How to fix “duplicate classes” error when building APK files?

So check both places and remove duplicate entries and the clean and build APK again. Show activity on this post. Delete files with duplicate jar extensions in the libs folder. However, if there are no duplicate files and there is still a "Duplicate classes" error, look for the name in the rest of the "Duplicate classes ...."


1 Answers

In my case the solution was to exclude xpp3

implementation(':B') { exclude module: 'xpp3' }

here is a nice explanation

like image 146
Comfy Cat Avatar answered Oct 06 '22 09:10

Comfy Cat