当前位置: 首页 > 知识库问答 >
问题:

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

西门经国
2023-03-14

我有4个错误消息时,我建立我的应用程序;当我添加了一个新的依赖项(de.westnordost:osmapi-注释: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个错误结束。那么,我需要使用的正确语法/组/模块是什么?

共有1个答案

杜晨朗
2023-03-14

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

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

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

 类似资料: