错误JSON.simple:java.util.zip.ZipException:重复条目:org/hamcrest/BaseDescription.class。

10

在添加 JSON.simple 并启用 MultiDex 后,我在 Android Studio 遇到了问题,并出现以下错误:

Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. java.util.zip.ZipException: duplicate entry: org/hamcrest/BaseDescription.class

这是我的 build.gradle 文件:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "com.MildlyGoodApps.EffortlessDescriptions"
    minSdkVersion 10
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true

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

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile 'com.android.support:multidex:1.0.0'
}

谢谢。

已修改:

compile 'com.googlecode.json-simple:json-simple:1.1.1'更改为compile('com.googlecode.json-simple:json-simple:1.1.1'){ exclude group: 'org.hamcrest', module: 'hamcrest-core' }.

谢谢Kane O'Riley!


1
这意味着您有两个或更多的dex文件定义了“org.hamcrest.BaseDescription”。也许可以发布您的“build.gradle”文件,并检查依赖项中是否存在此类重复条目。编写不良的库有时会直接包含外部依赖项类,而不是正确地引用它们。 - Kane O'Riley
添加了 build.gradle 文件。 - Peter Warrington
你的libs目录中有哪些JAR文件? - Kane O'Riley
2
你能否在项目目录下运行 ./gradlew -q api:dependencies --configuration compile 并将输出结果发布吗?另外,请尝试将 json-simple 的编译指令更改为以下形式:compile('com.googlecode.json-simple:json-simple:1.1.1') { exclude group: 'org.hamcrest', module: 'hamcrest-core' } - Kane O'Riley
1
很好。我已经发布了一个答案,如果它解决了你的问题,请点赞并接受它 :)。 - Kane O'Riley
显示剩余4条评论
1个回答

22

将您的 json-simple 导入更改为不包含 hamcrest 依赖项,如下所示:

更改成如下代码:

import com.googlecode.jsonsimple.JSONValue;
import com.googlecode.jsonsimple.parser.ParseException;

注意:这里只是去掉了 hamcrest 依赖项。

compile('com.googlecode.json-simple:json-simple:1.1.1') {
    exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
这将防止包含多个副本的依赖项。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接