gpt4 book ai didi

Android dex 在构建时给出 BufferOverflowException

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:26:52 25 4
gpt4 key购买 nike

当编译一个特定的 Android 项目时,并且只在我的 Windows 机器上,我从 dex 中得到一个 java.nio.BufferOverflowException。使用 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 构建工具:19.0.0。

最佳答案

无需将构建工具降级回 18.1.11,此问题为 fixed with build tools 19.0.1 .

如果您出于某种原因无法使用 19.0.1,则:

确保 android:targetSdkVersion 的值在 AndroidManifest.xml 中匹配 target=android-<value>project.properties 中。如果这两个值不相同,使用构建工具版本 19.0.0 构建将以 BufferOverflowException 结束。 Source

这篇文章的评论也表明您至少需要针对 19 (android-19)。如果您的目标是 < 19,如果此解决方案也适用,请发表评论。

This is how the fix looks为我的项目。 The related AOSP issue is #61710.

1 如果确实需要降级,不需要卸载build tools 19.0.0,只需安装18.1.1并添加sdk.buildtools=18.1.1即可到 local.properties文件。

关于Android dex 在构建时给出 BufferOverflowException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19825999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com