【问题标题】:Android - Duplicate Entry Error - How do I use one class from one JAR file when it exists in two JAR files without running into this error?Android - 重复条目错误 - 当一个 JAR 文件中的一个类存在于两个 JAR 文件中时,如何使用它而不遇到此错误?
【发布时间】:2015-06-24 17:14:34
【问题描述】:

当文件 ormlite-android-4.6.jar 和 ormlite-core-4.45.jar 中存在两个 JAR 文件中的相同类时,如何让我的代码仅使用一个 JAR 文件中的一个类而不会遇到此错误?

这是我的 build.gradle 文件的副本:

apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "com.android.engineering"
    minSdkVersion 16
    targetSdkVersion 21
    multiDexEnabled true
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}

packagingOptions {
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
}
}

dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.2.4'
compile 'joda-time:joda-time:2.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.android.support:appcompat-v7:22.0.0'
compile files('libs/achartengine-1.1.0.jar')
compile files('libs/butterknife-5.1.2.jar')
compile files('libs/com.google.guava_1.6.0.jar')
compile files('libs/com.springsource.org.junit-4.10.0.jar')
compile files('libs/commons-collections-3.2.1.jar')
compile files('libs/dagger-1.1.0.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/opencsv-3.3.jar')
compile files('libs/ormlite-android-4.6.jar')
compile files('libs/ormlite-core-4.45.jar')
compile files('libs/log4j-1.2.16.jar')
compile files('libs/icepick-2.3.jar')
compile files('libs/mockito-core-1.9.5.jar')
}

这是我得到的错误:

   :app:packageAllDebugClassesForMultiDex FAILED

   FAILURE: Build failed with an exception.
  • 出了什么问题: 任务 ':app:packageAllDebugClassesForMultiDex' 执行失败。

    java.util.zip.ZipException:重复条目:com/j256/ormlite/dao/BaseDaoImpl$1.class

  • 尝试: 使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。

    构建失败

    总时间:5.131 秒

我认为代码正在尝试使用 BaseDaoImpl.class,它都存在于 ormlite-android-4.6.jar 和 ormlite-core-4.45.jar 包中的 com.j256.ormlite.dao.BaseDaoImpl 中。如何让它使用一个 JAR 文件中的一个类而不遇到此错误?

【问题讨论】:

    标签: android jar android-studio build android-gradle-plugin


    【解决方案1】:

    你可以使用

       compile ("net.danlew:android.joda:2.9.0") {
            exclude group: 'org.joda.time'
        }
    

    或排除模块使用

    compile ("net.danlew:android.joda:2.9.0") {
        exclude module: 'jode-time'
    }
    

    【讨论】:

      【解决方案2】:

      运行“gradlew dependencies”,这将允许您查看所有库。您可以使用“排除”指令来删除重复的库。

      在此处阅读有关排除指令的更多信息:https://gradle.org/docs/current/userguide/dependency_management.html#sub:exclude_transitive_dependencies

      【讨论】:

        猜你喜欢
        • 2021-10-14
        • 1970-01-01
        • 1970-01-01
        • 2013-07-08
        • 1970-01-01
        • 2020-05-14
        • 2011-04-30
        • 1970-01-01
        • 2020-01-27
        相关资源
        最近更新 更多