Android transformClassesWithDexForAdh5Debug 的解決方法

1 遇到的問題

開發中遇到下面一個運行錯誤:


Error:Execution failed for task ':hello_v1.0:transformClassesWithDexForAdh5Debug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\Program Files\Java\jdk1.8.0_65\bin\java.exe'' finished with non-zero exit value 2
> 

如果使用了友盟或者百度地圖,則還會在運行時報下面一排警告:

Warning:Ignoring InnerClasses attribute for an anonymous inner class
(org.dom4j.swing.LeafTreeNode$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

如下圖:

這裏寫圖片描述

這裏寫圖片描述

這裏寫圖片描述

2 原因

博主是在集成一個庫的時候,編譯通過,運行時報上面的錯誤,可是之前集成過一次,明明可以運行的,同樣的方法再次集成就不行了。最後發現是因爲方法數太多了,超過了限制

3 解決方法

在build.gradle中添加下面代碼:

defaultConfig {
    ......   
    multiDexEnabled true
}

4 參考鏈接

我是參考下面的博客解決問題的:

http://blog.csdn.net/zouchengxufei/article/details/50011237

順便貼一下StackOverflow上關於這個問題的解答:

http://stackoverflow.com/questions/33095536/apptransformclasseswithdexfordebug-com-Android-build-transform-api-transf

5 轉載請註明來自”梧桐那時雨”的博客:http://blog.csdn.net/fuchaosz/article/details/51398071

Tips:
如果覺得這篇博客對你有幫助或者喜歡博主的寫作風格,就給博主留個言或者頂一下唄,鼓勵博主創作出更多優質博客,Thank you.

發佈了34 篇原創文章 · 獲贊 338 · 訪問量 90萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章