在Gradle中发现的重复类:如何定义要排除的组和模块?



我有4个错误信息,当我建立我的应用程序;当我添加一个新的依赖(de.westnordost:osmapi-notes:1.3)时,它们出现了。这些消息都是相似的:

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)

依赖项是:

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

我看了看这个线程,它对找到解决方案有很长的路要走,但我无法找出正确的组和模块来排除。这三种方法我都试过了:

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

但它们最终都得到了相同的4个错误。那么,我需要使用的正确语法/组/模块是什么?

通常会像这样排除它(这似乎足够了):

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

org.osmdroid:osmdroid-mapsforge:6.1.8也有这些类,但可能比xmlpull多一些代码。因为它们没有相同的包名,你最终可以(如果排除不起作用)用Gradle Shadow Plugin重新定位其中一个,并通过通配符org.xmlpull.v1.*排除。

尝试用这种方式排除

implementation('de.westnordost:osmapi-notes:1.3') {
exclude group: 'net.sf.kxml', module: 'kxml2'
exclude group: 'xmlpull', module: 'xmlpull'
exclude group: 'xpp3', module: 'xpp3'
}

最新更新