Android dex gives a BufferOverflowException when building
Solution 1
No need to downgrade the build tools back to 18.1.11, this issue is fixed with build tools 19.0.1.
If you can't use 19.0.1 for some reason then:
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
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.
This is how the fix looks for my project. The related AOSP issue is #61710.
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.
Solution 2
Try what van said:
Right click your project
→ android tools
→ android support library
.
Hope this helps :)
Solution 3
Same problem here. Reverted to build tools 18.1.1, restarted Eclipse and that fixed it.
Solution 4
I was able to get my problem project to build by adding this extra line:
sdk.build.tools=18.1.1
...to my project.properties file, which is present in the root of the project folder. All other approaches seemed to fail for me.
Solution 5
After the installation of the new SDK, there is a new folder, "Android Dependencies", under your project file. If you right click and remove it from the build path, you will again be able to build your project.
Related videos on Youtube
beetstra
Updated on March 17, 2020Comments
-
beetstra over 4 years
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.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
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.
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.
-
Sherif elKhatib over 10 yearsDo you use libraries? Check their setup
-
beetstra over 10 years@SherifelKhatib, just the support library and Google Analytics V2
-
CommonsWare over 10 yearsSince nobody seemed to have filed an issue on this yet, I have filed one at: code.google.com/p/android/issues/detail?id=61710
-
vpathak over 10 yearstrying by removing all android sdk , eclipse , and code.
-
isti_spl over 10 yearsgetting simiar error on Centos x64: !SESSION 2013-11-07 17:07:35.305 eclipse.buildId=v22.3.0-887826 java.version=1.7.0_40 java.vendor=Oracle Corporation BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US Framework arguments: -product com.android.ide.eclipse.adt.package.product Command-line arguments: -os linux -ws gtk -arch x86_64 -product com.android.ide.eclipse.adt.package.product java.nio.BufferOverflowException at java.nio.Buffer.nextPutIndex(Buffer.java:519)
-
-
beetstra over 10 yearsYep, that fixed it. Had to manually delete the old 19.0.0 directory though.
-
NickT over 10 yearsThis fixed it for me also, though I reverted to 18.0.1
-
Christopher over 10 yearsThank you for this solution, just two clicks and the problem was solved!!!!! (although in my menu, it was "add support library")
-
Jayesh over 10 yearsFrom where I can install adt bundle ?
-
Jayesh over 10 yearsWhat about API level below 18 ? How can we run application below API level 18 ?
-
Jon over 10 yearsI used this answer and I didn't have to revert back: stackoverflow.com/questions/19727915/…
-
saurav over 10 yearsi think this is also one of the reason behind the problem. I never used version 19 in my target sdk and still the problem was coming. Probably the sdk build tools was set to 19 which had to be reverted back
-
James Wald over 10 yearsThis didn't work for me. Verified all project.properties and targetSdk. I am using the latest version of IntelliJ IDEA 13 Cardea. Fortunately, uninstalling build-tools 19.0.0 did fix the build.
-
James Wald over 10 yearsI verified all project.properties and targetSdk. I am using the latest version of IntelliJ IDEA 13 Cardea and played with the project's SDK version as well. Uninstalling build-tools 19.0.0 was the only way to fix the build for my project.
-
Darren over 10 yearsThanks. Reverting to build tools 18.1.1 and deleting 19 fixed this for me. I thought I was going crazy
-
Flow over 10 yearsThe used target does not determine the used buildtools version.
-
RolandK over 10 yearsFor me to make it work, I also had to set the target SDK to the latest version (19).
-
Swanand over 10 years@Stefano: I am interested in knowing, how did you conclude this is what you had to do?
-
Salsero69 over 10 yearsI noticed that this folder would cause a duplicate JAR issue. But deleting it didn't resolve my problem.
-
Mahendra Liya over 10 years@Salsero69 Are you using a library project as a reference in your actual project?
-
mrmoment over 10 yearsAnd also make sure the target sdk version is downloaded with your sdk manager (this is my problem's cause).
-
speedynomads over 10 yearsI added the latest support library and added this line to the project properties and my problem was fixed... thanks
-
Javier Sedano over 10 yearsJust to let others know: no need to downgrade, the answer from Flow is better.
-
thomasa88 over 10 yearsI had target 10 in both AndroidManifest.xml and project.properties. Tried restarting Eclipse and cleaning, but did not help. Then I set target to 19 in config.properties and it worked. Have not tried downgrading build tools. (Target 15 did not work)
-
Zach Mcgregor over 10 yearsI'm surprised this worked; it's in the AOSP source as
sdk.buildtools
, notsdk.build.tools
, and that was the name that worked for me. -
Jaldip Katre over 10 yearsSetting targetSdkVersion in manifest and target in properties, to 19 worked for me
-
PiersyP over 10 yearsMy target api level was set to 10 in both the manifest and project properties, for me only downgrading to SDK Build-tools 17 (since I didn't have 18 installed) worked. (Im using intellij 13 by the way)
-
Peter Mortensen over 10 yearsHow did you change the API level to 16?
-
Zsolt Boldizsar over 10 yearsI simply right clicked my project, and selected Android from the list. It should show up a list of installed android API versions, select the one which has 16 as API level(4.1.2).
-
Ahmed Khalaf over 10 yearsThank you. Target sdk in the manifest and the target in the .properties file must be the same. Worked for me.
-
Robert over 10 yearsYes, this issue seems fixed in 19.0.1. Also worked fine with "ant debug".
-
twlkyao over 10 years@JD.com it worked for me, but why should we change that to 19?
-
Jaldip Katre over 10 years@twlkyao Well the name "target" itself states the requirement, Probably this was not required in SDK tools version less than 22.3
-
twlkyao over 10 years@JD.com Does this mean we have to update the targetSDK to the latest version?
-
Jaldip Katre over 10 years@twlkyao No, Only the targetSdkVersion in manifest and target in project.propeeties must be the same value
-
twlkyao over 10 years@JD.com But why only have I to set them to 16 and above that can solve the issue.
-
Pratik Butani over 10 years
target=android-17
is must equals toandroid:targetSdkVersion="17"
-
AfromanJ over 10 yearsIs it possible to get this to work when using
target=android-15
? -
user914425 almost 9 yearsI had to add project->Android Tools->Add Support Library and it install ADT 19.0.1 Support Library. After that it generates apk fine.