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

Comfy Cat :

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?

Comfy Cat :

In my case the solution was to exclude xpp3

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

here is a nice explanation

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=141288&siteId=1