当编译一个特定的Android项目时,并且仅在我的Windows计算机上,我java.nio.BufferOverflowException
从dex中获得了。使用Eclipse和使用Ant时均会发生此问题。
使用Ant时的输出为:
...
[dex] Pre-Dexing C:\MyProject\libs\android-support-v4.jar -> android-support-v4-5f5341d3c1b10a79d7d93f9c1e64421e.jar
[dex] Converting compiled files and external libraries into C:\MyProject\bin\classes.dex...
[dx]
[dx] UNEXPECTED TOP-LEVEL EXCEPTION:
[dx] java.nio.BufferOverflowException
[dx] at java.nio.Buffer.nextPutIndex(Buffer.java:499)
[dx] at java.nio.HeapByteBuffer.putShort(HeapByteBuffer.java:296)
[dx] at com.android.dex.Dex$Section.writeShort(Dex.java:818)
[dx] at com.android.dex.Dex$Section.writeTypeList(Dex.java:870)
[dx] at com.android.dx.merge.DexMerger$3.write(DexMerger.java:437)
[dx] at com.android.dx.merge.DexMerger$3.write(DexMerger.java:423)
[dx] at com.android.dx.merge.DexMerger$IdMerger.mergeUnsorted(DexMerger.java:317)
[dx] at com.android.dx.merge.DexMerger.mergeTypeLists(DexMerger.java:423)
[dx] at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:163)
[dx] at com.android.dx.merge.DexMerger.merge(DexMerger.java:187)
[dx] at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
[dx] at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
[dx] at com.android.dx.command.dexer.Main.run(Main.java:230)
[dx] at com.android.dx.command.dexer.Main.main(Main.java:199)
[dx] at com.android.dx.command.Main.main(Main.java:103)
BUILD FAILED
C:\Users\Jaap\android-sdks\tools\ant\build.xml:892: The following error occurred while executing this line:
C:\Users\Jaap\android-sdks\tools\ant\build.xml:894: The following error occurred while executing this line:
C:\Users\Jaap\android-sdks\tools\ant\build.xml:906: The following error occurred while executing this line:
C:\Users\Jaap\android-sdks\tools\ant\build.xml:284: null returned: 2
使用Eclipse时,该消息较短但类似:
[2013-11-01 14:29:44] APK file is not created for Project:
[2013-11-01 14:29:46 - Dex Loader] Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
[2013-11-01 14:29:46 - MyProject] Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
就像我说的,我的MacBook上没有这个问题,即使它们都已升级到最新版本的Android Build工具:19.0.0。