【问题标题】:Duplicate class org.apache.commons重复类 org.apache.commons
【发布时间】:2020-10-09 18:20:09
【问题描述】:

我正在尝试在 Android 上运行构建。我正在为 Java 库构建 React-Native 桥接器。但是,我收到Duplicate class 错误,如下所示:

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

如果能帮助我找到解决此问题的方法,我将不胜感激。提前致谢。

【问题讨论】:

    标签: java android react-native build.gradle react-native-android


    【解决方案1】:

    依赖的配置闭包的 exclude 方法排除了传递依赖。因此,如果您的模块依赖项依赖于其他模块,您可以将它们从构建中排除。您可以在其 maven repo 上查看 'com.facebook.react:react-native:+' 模块的传递依赖关系。 https://mvnrepository.com/artifact/com.facebook.react/react-native/0.20.1

    尝试指定依赖的版本而不是使用'+'以避免冲突。

    这里是检查解决插件和依赖 jar 冲突的一些参考。

    jarjar package reference

    【讨论】:

      猜你喜欢
      • 2013-04-04
      • 2015-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      • 2016-12-28
      • 2020-09-15
      • 2011-01-09
      相关资源
      最近更新 更多