我正在尝试在Android上运行一个构建。 我正在为Java的一个图书馆建造一座React-Native桥梁。 但是,我收到一个重复类
错误,如下所示:
Duplicate class org.apache.commons.lang3.builder.CompareToBuilder
found in modules commons-lang3-3.9.jar (org.apache.commons:commons-lang3:3.9)
and creditCardNfcReader-1.0.3-runtime.jar (com.github.pro100svitlo:creditCardNfcReader:1.0.3)
这些错误有一个完整的列表被打印出来。 还有一个略有不同的错误,如下所示:
Duplicate class bolts.BoltsExecutors$ImmediateExecutor found in
modules bolts-tasks-1.4.0.jar (com.parse.bolts:bolts-tasks:1.4.0)
and jetified-bolts-android-1.1.2.jar (com.parse.bolts:bolts-android:1.1.2)
我的依赖项当前在我的build.gradle文件中如下所示:
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+"
implementation 'com.github.pro100svitlo:creditCardNfcReader:1.0.3'
addUnimodulesDependencies()
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
我已经尝试从依赖项中排除模块和组,但还没有成功。 以下是我尝试过的几种方法,这些方法是从几个来源推荐的:
1。
implementation ("com.facebook.react:react-native:+") {
exclude group: 'com.parse.bolts', module: 'bolts-tasks'
}
2。
implementation ("com.facebook.react:react-native:+") { exclude module: 'bolts-tasks'}
3。
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+"
implementation 'com.github.pro100svitlo:creditCardNfcReader:1.0.3'
addUnimodulesDependencies()
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
configurations { runtime.exclude group: '*' }
如果你能帮我找到解决这个问题的办法,我将不胜感激。 提前谢谢你。
依赖项的配置闭包的exclude方法排除可传递依赖项。 因此,如果您的模块依赖关系依赖于其他模块,则可以从您的构建中排除它们。 您可以在maven repo上查看'com.facebook.react:react-native:+'模块的传递依赖项。 https://mvnrepository.com/artifact/com.facebook.react/react-native/0.20.1
请尝试指定依赖项的版本,而不是使用“+”以避免冲突。
这里有一些参考来检查如何解决插件和依赖项jar冲突。
jarjar包参考