Error處理: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.
導入Eclipse Android2.X項目後運行,提示報錯:
Console中提示:
通過clean up,fix project之後問題均不能解決。
網上還看到有人說,是因爲Eclipse stack的問題,調整之後可以解決問題;按此提示,eclipse.ini的內容如下:
- -startup
- plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
- --launcher.library
- plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.100.v20110502
- -product
- org.eclipse.epp.package.java.product
- --launcher.defaultAction
- openFile
- --launcher.XXMaxPermSize
- 512M
- -showsplash
- org.eclipse.platform
- --launcher.XXMaxPermSize
- 256m
- --launcher.defaultAction
- openFile
- -vmargs
- -Dosgi.requiredJavaVersion=1.5
- -Xms512m
- -Xmx1024m
重啓eclipse之後,運行,問題依舊。
如何解決?
之前也遇到過代碼沒有錯誤,就是編譯運行時報錯的情況。之前是因爲引用第三方jar造成的,引用方式不對造成的,結合目前的狀況,
後來goolge上看到:http://code.google.com/p/android/issues/detail?id=20398帖子中的:
- Here is differences between old and new:
- (old)
- <?xml version="1.0" encoding="UTF-8"?>
- <classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="gen"/>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="src" path="andengine_src"/> <!-- NOTICE THIS LINE -->
- <classpathentry kind="output" path="bin"/>
- </classpath>
- (new)
- <?xml version="1.0" encoding="UTF-8"?>
- <classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="gen"/>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> <!-- NOTICE THIS LINE -->
- <classpathentry kind="output" path="bin/classes"/>
- </classpath>
- Also, new .project file does not contain <linkedResources> section
認爲下面調整引用庫的方式比較靠譜。於是根據這個思想進行調整項目的.classpath
我的.classpath文件內容如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <classpath>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="gen"/>
- <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
- <classpathentry kind="lib" path="libs/achartengine-1.1.0.jar"/>
- <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
- <classpathentry kind="output" path="bin/classes"/>
- </classpath>
調整之後如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="gen"/>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="lib" path="libs/achartengine-1.1.0.jar"/>
- <classpathentry kind="output" path="bin/classes"/>
- </classpath>
之後Refresh--->>Clean UP--->>運行項目,一切正常,至此問題解決。
----------
備註說明:
對於這個問題,發現在升級SDK Tool到22.3之後,也就是Android 4.4的SDK及工具之後,加載之前老版本的項目都會出現這個問題。
關鍵是要將.classpath文件中的:
- <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、重新編譯運行。