【问题标题】:Android: Error:Execution failed for task app:transformClassesWithPreJackPackagedLibrariesForDebugAndroid:错误:任务应用程序执行失败:transformClassesWithPreJackPackagedLibrariesForDebug
【发布时间】:2017-05-31 12:55:20
【问题描述】:

我在尝试运行我的 Android 程序时遇到此错误。

错误:任务“:app:transformClassesWithPreJackPackagedLibrariesForDebug”执行失败。 java.lang.AssertionError:java.util.zip.ZipException:重复条目: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 中编写了很多函数。

【问题讨论】:

    标签: android android-studio java-8


    【解决方案1】:

    我也有同样的问题。我相信com.android.support.test.espresso:espresso-core:2.2.2 是用hamcrest 编译的,我认为com.android.support:appcompat-v7:25.3.1 也是用hamcrest 编译的。我相信错误消息告诉您 hamcrest 包包含在至少两个已编译的 jar 中,并且它无法解决重复的问题(即使它们是相同的版本)。由于 Jack 的一些技术性,它可能无法解决重复问题。要解决这个问题,您只需要将其排除在其中一个之外:

    `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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-29
      • 2016-05-13
      • 2018-11-08
      • 1970-01-01
      • 2016-10-20
      • 2015-02-14
      • 2015-08-16
      相关资源
      最近更新 更多