Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException,androidexception
異常Log:
Error:Execution failed for task ‘:app:dexDebug’.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/Library/……/java” finished with non-zero exit value 2
錯誤原因:
這個異常在Android Studio編譯啟動並執行時候出現,原因是項目中引用了重複的jar包,這可能是因為新引入的library module中有和主專案中重複引用的jar包,需要重點檢查 Android 相容包 support-v4 和 support-v7 包,還有一些常用的開源項目,例如Gson,Nineoldandroids…,這些常用的開源項目有可能在你引用的 library 項目中已經被引用過了。
解決辦法:
解決這個問題我們只需要刪除主專案中 libs 檔案夾中和 library中重複的部分即可,另外,我推薦大家改變將 jar 包放在 libs 目錄中的習慣,而使用 Gradle 構建,在 module 下的 build.gradle 目錄下將
dependencies { compile files('libs/nineoldandroids-2.4.0.jar')}
或
dependencies { compile fileTree(dir: 'libs', include: ['*.jar'])}
改為
dependencies { compile 'com.nineoldandroids:library:2.4.0'}
在參考連結中,我發現一個類似的異常
Error:Execution failed for task ‘:app:dexDebug’.
> com.android.ide.common.internal.LoggedErrorException
出現這個錯誤是因為主專案和Library項目中都引用了 compile ‘com.nineoldandroids:library:2.4.0’ ,但我在最新的 Android Studio 1.3 Preview 和 Gradle 2.3中給主專案和Library項目進行了一次類比,卻沒有出現該異常,根據問題中給出了 build.gradle 檔案,這可能是因為使用了低版本Android Studio 或 Gradle 的緣故,所以大家最好還是在項目中檢查一下,library項目中已經引入的jar,library就不要再引入到主專案中了。
參考連結:
http://stackoverflow.com/questions/27675717/gradle-error-execution-failed-for-task-appdexdebug/27675841