Android的地塞米松给人以BufferOverflowException建设时,给人以、Android、BufferOverflowException

2023-09-11 11:11:28 作者:少年与狗 #

当,只有在我的Windows机器编译一个特定的Andr​​oid项目,我收到了 java.nio.BufferOverflowException 从DEX期间。出现该问题的两种使用Eclipse时使用Ant时。

When compiling a specific Android project, and only on my Windows machine, I get a java.nio.BufferOverflowException during from dex. The problem occurs both when using Eclipse and when using Ant.

使用Ant时的输出是:

The output when using Ant is:

...
  [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的消息较短,但类似的:

When using Eclipse the message is shorter but similar:

[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构建工具的最新版本:19.0.0

Like I said, I don't have this problem on my MacBook, even though they are both upgraded to the latest versions of the Android Build tools: 19.0.0.

推荐答案

无需降级构建工具回18.1.1 1 ,这个问题的固定的编译工具19.0.1

No need to downgrade the build tools back to 18.1.11, this issue is fixed with build tools 19.0.1.

如果您无法使用19.0.1由于某些原因:

If you can't use 19.0.1 for some reason:

请确保的 Android的价值:targetSdkVersion 在 AndroidManifest.xml中匹配目标= android-<价值&GT ; 在 project.properties 。如果这两个值是不一样的,建设有构建工具的版本19.0.0将结束在BufferOverflowException。 Source

Make sure that the value of android:targetSdkVersion in AndroidManifest.xml matches target=android-<value> in project.properties. If these two values are not the same, building with build tools version 19.0.0 will end in the BufferOverflowException. Source

也有一些迹象表明,从对这个职位,你需要的目标至少有19(机器人-19)的意见。请发表评论,如果这个解决方案也适用,如果你的目标为&lt; 19。

There is also some indication from comments on this post that you need to target at least 19 (android-19). Please leave a comment if this solution also works if your target is < 19.

这是怎样的修复看上去我的项目。 的相关AOSP的问题是#61710。

1。如果你真的需要降级,你不需要卸载构建工具19.0.0,只需安装18.1.1,并添加 sdk.buildtools = 18.1.1 local.properties 文件。

1 If you really need to downgrade, you don't need to uninstall build tools 19.0.0, simply install 18.1.1 and add sdk.buildtools=18.1.1 to the local.properties file.