Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
6.4k views
in Technique[技术] by (71.8m points)

android - Duplicate classes found in Gradle: How to define a group and module to exclude?

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.*.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...