1

I have 4 error messages when I build my app; they appeared when I addded a new dependency (de.westnordost:osmapi-notes:1.3). The messages are all similar:

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

The dependencies are:

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.navigation:navigation-fragment:2.3.2'
implementation 'androidx.navigation:navigation-ui:2.3.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'org.osmdroid:osmdroid-android:6.1.8'
implementation 'org.osmdroid:osmdroid-wms:6.1.8'
implementation 'org.osmdroid:osmdroid-mapsforge:6.1.8'
implementation 'org.osmdroid:osmdroid-geopackage:6.1.8'
implementation 'org.osmdroid:osmdroid-third-party:6.0.1'
implementation 'com.github.MKergall:osmbonuspack:6.6.0'
implementation 'de.westnordost:osmapi-notes:1.3'
}

I have looked at this thread which goes a long way towards finding a solution but I cannot work out the correct group and module to exclude. I have tried all three of these:

configurations {
   /* runtime.exclude group: "org.xmlpull" , module: "xmlpull"*/
   /* runtime.exclude group: "net.sf.kxml" , module: "kxml2"*/
    runtime.exclude group: "org.xmlpull" , module: "jetified-xmlpull-1.1.3.1"
}

but they all end up with the same set of 4 errors. So, what is the correct syntax / group / module that I need to use?

quilkin
  • 874
  • 11
  • 31
  • The approach you follow there is questionable. Why you don't provide the dependencies block? Unless you'd make the issue which you describe reproducible, this otherwise simple question is rather difficult to answer. – Martin Zeitler Jan 19 '21 at 22:54
  • @MartinZeitler, dependencies added. The approach has a lot of upvotes in the link I gave. – quilkin Jan 19 '21 at 23:21
  • This is based upon popularity and not necessarily quality; upvotes are often the most stupid Q&A and one may also find correct answers downvoted, because people fail to apply them. While I have something to copy & paste, I probably can answer that ... – Martin Zeitler Jan 19 '21 at 23:26

2 Answers2

2

Usually one would exclude it alike this (which appears to suffice):

implementation ("de.westnordost:osmapi-notes:1.3") {
    exclude group: "xmlpull", module: "xmlpull"
}

org.osmdroid:osmdroid-mapsforge:6.1.8 also has these classes, but likely some more code than xmlpull. Since they do not have the same package name, you could eventually (if the exclude wouldn't work) relocate one of them with the Gradle Shadow Plugin and exclude by wildcard org.xmlpull.v1.*.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • It works, great, thanks - no need for the shadow plugin. In view of your earlier comments, should I go back to my earlier findings and upvote/downvote as appropriate? – quilkin Jan 20 '21 at 09:53
  • I just left the third one option there, because in some cases it's the last resort (when having identical class names with different functionality)... but in this case, `kxml2` is just badly packaged. One almost would have to `diff` the files to make sure that they're really the same. – Martin Zeitler Jan 20 '21 at 14:35
0

Try to use this way to exclude

implementation('de.westnordost:osmapi-notes:1.3') {
    exclude group: 'net.sf.kxml', module: 'kxml2'
    exclude group: 'xmlpull', module: 'xmlpull'
    exclude group: 'xpp3', module: 'xpp3'
}
klim
  • 11
  • 2
  • Your decision with only this one line "exclude group: "xmlpull", module: "xmlpull"" does not working. Have you tried it? https://ibb.co/0rdMYXH – klim Jan 20 '21 at 00:03