2017-05-31 151 views
3

我試圖運行我的Android程序時出現此錯誤。Android:錯誤:任務應用程序執行失敗:transformClassesWithPreJackPackagedLibrariesForDebug

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

回答

0

寫道:我有同樣的問題。我相信com.android.support.test.espresso:espresso-core:2.2.2是用hamcrest編譯的,我認爲com.android.support:appcompat-v7:25.3.1也是用hamcrest編譯的。我相信錯誤信息告訴你,hamcrest包至少包含在兩個編譯的jar中,並且它不能解決重複的問題(即使它們是相同的版本)。它可能無法解決由於一些傑克技術性造成的重複。爲了解決這個問題,你只需要從一個或另一個排除:

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

}) 

,或者如果你不是真的用咖啡核,只是刪除androidTestCompile線完全。

在我的情況,我也不得不補充:

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

,因爲我得到一個稍微不同的錯誤是由於包括兩個不同的JUnit版本衝突。

調試這類錯誤的最佳方法是使用命令行中的gradle。

  1. 打開命令提示符
  2. 導航到項目目錄(它包含gradlew.bat)
  3. gradlew app:androidDependencies

相關問題