Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException.

Error處理:Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException.

分類: Android 動手操作 4404人閱讀 評論(7) 收藏 舉報

Error處理:Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException.


導入Eclipse Android2.X項目後運行,提示報錯:


Console中提示:


通過clean up,fix project之後問題均不能解決。


網上還看到有人說,是因爲Eclipse stack的問題,調整之後可以解決問題;按此提示,eclipse.ini的內容如下:


[html] view plaincopy
  1. -startup  
  2. plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar  
  3. --launcher.library  
  4. plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.100.v20110502  
  5. -product  
  6. org.eclipse.epp.package.java.product  
  7. --launcher.defaultAction  
  8. openFile  
  9. --launcher.XXMaxPermSize  
  10. 512M  
  11. -showsplash  
  12. org.eclipse.platform  
  13. --launcher.XXMaxPermSize  
  14. 256m  
  15. --launcher.defaultAction  
  16. openFile  
  17. -vmargs  
  18. -Dosgi.requiredJavaVersion=1.5  
  19. -Xms512m  
  20. -Xmx1024m  

重啓eclipse之後,運行,問題依舊。

如何解決?


之前也遇到過代碼沒有錯誤,就是編譯運行時報錯的情況。之前是因爲引用第三方jar造成的,引用方式不對造成的,結合目前的狀況,

後來goolge上看到:http://code.google.com/p/android/issues/detail?id=20398帖子中的:


[html] view plaincopy
  1. Here is differences between old and new:  
  2.   
  3. (old)  
  4. <?xml version="1.0" encoding="UTF-8"?>  
  5. <classpath>  
  6.     <classpathentry kind="src" path="src"/>  
  7.     <classpathentry kind="src" path="gen"/>  
  8.     <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>  
  9.     <classpathentry kind="src" path="andengine_src"/> <!-- NOTICE THIS LINE -->  
  10.     <classpathentry kind="output" path="bin"/>  
  11. </classpath>  
  12.   
  13. (new)  
  14. <?xml version="1.0" encoding="UTF-8"?>  
  15. <classpath>  
  16.     <classpathentry kind="src" path="src"/>  
  17.     <classpathentry kind="src" path="gen"/>  
  18.     <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>  
  19.     <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>  <!-- NOTICE THIS LINE -->  
  20.     <classpathentry kind="output" path="bin/classes"/>  
  21. </classpath>  
  22.   
  23. Also, new .project file does not contain <linkedResources> section  

認爲下面調整引用庫的方式比較靠譜。於是根據這個思想進行調整項目的.classpath


我的.classpath文件內容如下:

[html] view plaincopy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <classpath>  
  3.     <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>  
  4.     <classpathentry kind="src" path="src"/>  
  5.     <classpathentry kind="src" path="gen"/>  
  6.     <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>  
  7.     <classpathentry kind="lib" path="libs/achartengine-1.1.0.jar"/>  
  8.     <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>  
  9.     <classpathentry kind="output" path="bin/classes"/>  
  10. </classpath>  

調整之後如下:

[html] view plaincopy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <classpath>  
  3.     <classpathentry kind="src" path="src"/>  
  4.     <classpathentry kind="src" path="gen"/>  
  5.     <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>  
  6.     <classpathentry kind="lib" path="libs/achartengine-1.1.0.jar"/>  
  7.     <classpathentry kind="output" path="bin/classes"/>  
  8. </classpath>  

之後Refresh--->>Clean UP--->>運行項目,一切正常,至此問題解決。


----------

備註說明:

對於這個問題,發現在升級SDK Tool到22.3之後,也就是Android 4.4的SDK及工具之後,加載之前老版本的項目都會出現這個問題。

關鍵是要將.classpath文件中的:

[html] view plaincopy
  1. <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>  

· 去掉,之後clean up整個項目,再重新編譯即可。


後續說明(2013年11月20日):

對於這個問題,最近大家可能比較苦惱,我也發現並不是所有的項目都會出現這個問題,對於具體差異和原因有待以後遇到再深入探究吧。

不過遇到這個問題的項目,凡是經過以下方法處理的都能夠正常進行編譯和運行。

1、找到你的項目


2、點擊右鍵


3、打開Properties屬性項


4、選中左邊Java Build Path項,並在該選項中打開Libraries選項卡,如上圖中,將Android Dependencies項和Android Private Libraries這兩項Remove掉。

5、Clean up該項目

6、重新編譯運行。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章