Android:错误:执行任务app时失败:transformClassesWithPreJackPackagedLibrariesForDebug

4

当我试图运行我的Android程序时,出现了以下错误。

Error:Execution failed for task ':app:transformClassesWithPreJackPackagedLibrariesForDebug'. java.lang.AssertionError: java.util.zip.ZipException: duplicate entry: jayce/org/hamcrest/BaseDescription.jayce

这是我的build.gradle文件。

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
    applicationId "com.surgical.decision"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    jackOptions {
        enabled true
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile files('libs/simple-xml-2.7.1.jar')
compile files('libs/log4j-1.2.17.jar')
compile files('libs/pddl4j-3.5.0.jar')
}

我必须启用jackOptions,因为我的许多函数是在Java 8中编写的。

1个回答

0

我曾经遇到过同样的问题。我相信 com.android.support.test.espresso:espresso-core:2.2.2 是使用 hamcrest 编译的,而 com.android.support:appcompat-v7:25.3.1 也是使用 hamcrest 编译的。我认为错误信息告诉你至少有两个编译的 jar 包含了 hamcrest 包,它无法解决重复问题(即使它们是相同版本)。由于某些 Jack 技术上的技术性原因,它可能无法解决重复问题。要解决这个问题,你只需要从其中一个中排除它即可:

i.e

`androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude group: 'org.hamcrest', module: 'hamcrest-core'

})

如果您并没有真正使用espresso-core,那么可以完全删除androidTestCompile这一行。

在我的情况下,我还需要添加:

exclude group: 'junit', module: 'junit'

因为我由于包含两个不同的junit版本冲突而得到了稍微不同的错误。

调试这些类型的错误的最佳技术是使用命令行中的gradle。

  1. 打开命令提示符
  2. 导航到项目目录(其中包含gradlew.bat)
  3. gradlew app:androidDependencies


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