Android - 重复条目错误 - 当一个 JAR 文件中的一个类存在于两个 JAR 文件中时,如何使用它而不会遇到此错误?

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

当文件 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: duplicate entry: 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 文件中的一个类而不遇到此错误?

最佳答案

您可以使用

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

关于Android - 重复条目错误 - 当一个 JAR 文件中的一个类存在于两个 JAR 文件中时,如何使用它而不会遇到此错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29706209/

相关文章:

android - 如何给图片按钮添加点击效果?

Java 无法识别的选项 : -xvf

AndroidStudio 0.8.2 运行应用程序或调试应用程序失败

android-studio - 我在 Android-Studio 2.1.2 中下载插件时启用了 "Run in background"。现在我找不到办法再次启用它。该怎么办?

android - "D/Notification: allPendingIntents"更新通知时记录

android - 在 Android 中使用单例模式如何影响内存使用?

android - 如何从图库中获取图像并在 Android 应用程序中移动

java - 如何在 clojure 中访问一 jar jar ?

java - 在 maven 中使用/导入本地 fat jar 作为插件

java - 从 Android Studio 3.3 升级后,Android Studio 3.4 在加载项目时卡住