Android dex gives a BufferOverflowException when building - android

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.

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.

Try what van said:
Right click your project → android tools → android support library.

Same problem here. Reverted to build tools 18.1.1, restarted Eclipse and that fixed it.

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.

Right click on project >> Properties >> Android >> API Level 18 worked for me. But before I did that I did right click on project >> Android Tools >> Add Support Library and restarted Eclipse. You may have to play around with your selected API level.

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.

Update
right click your project > android tools > android support library
Clean your project and try to built.

I had the same problem after updating to Revision 19. Just do not forget to update ADT, https://dl-ssl.google.com/android/eclipse/. After this, I was able to build project with the latest revision.

I fixed this problem without downloading the support library or reverting the build tools to 18.1.1.
I simply changed the API level to 16+ and the problem vanished. Hope it will help.

None of the other solutions here worked for me after upgrading to Android Studio 0.4.0 and Gradle 1.9.
I resolved the problem by downloading Build Tools 19.0.1 and updating the following line in my build.gradle files:
buildToolsVersion '19.0.0'
to
buildToolsVersion '19.0.1'

For the ones facing issue with IntelliJ IDEA 13, uninstall Build Tools 19.

Had the same issue with target version 19 on both project.properties and AndroidManifest.xml with Ant.
Fixed it by:
Uninstalled Android SDK Build-Tools 19.0.1
Installed Android SDK Build-Tools 19.0.2
I think #Al-Kathiri-Khalid is spot on. The issue is only due to missing support for the API level in Build Tools.

I had the same problem, though my project did not use the support library. Adding libs/android-support-v4.jar to the project worked around the problem without needing to revert the build tools back from v19.

I solved this problem. Just make this change in the project properties file:
target=android-18
sdk.build.tools=18.1.1
And in the manifest file:
uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="18"

Add the Library file in project..
Project->right click->Properties->android->Library-> click Add and select the Library Project and give apply and ok..
then, clean the project and run again.. if you want restart the eclipse..
And also, sometimes, need to update Android SDK build tools..

What worked for me was this:
I opened the project.properties file from the root of my project and changed target=android-8 to target=android-17

java.nio.BufferOverflowException during from dex error
This means you don't have the supporting API for that level hence the build fails, there are a number of ways you can fix this.
Check your manifest file uses-sdk android:minSdkVersion="4" and android:targetSdkVersion="14"
Any of the below will fix the problem:-
Download the required API level (This might take time) and run your application again
Quick dirty fix change your Project target in project.properties
to your new target target=android-4
Quick clean fix, change the SdkVersion in your manifest and Clean
your project to add the changes to your project.properties (My favorite)

I removed the previous Android SDK and Eclipse. I installed the ADT bundle and it works...
This fixed the problem of BufferOverflow on Dex that started after I got API 19. I was previously using Eclipse with Android SDK installed as an add-on package.

Right click on Project>>Properties>>Android and select API Level greater than 15
OR
Add google-play-services_lib to your project by right clicking on project and selecting Project>>Properties>>Android>>Add

Related

Build path error when creating android project in Eclipse

When creating a new android application i get the following error messages.
Project 'appcompat_v7' is missing required source folder: 'gen' appcompat_v7 Build path Build Path Problem
The container 'Android Dependencies' references non existing library '/Users/Edvin/Documents/Edvins Workspace/appcompat_v7/bin/appcompat_v7.jar' MyFirstAndroidApp. Build path Build Path Problem
Im using Android 5.1.1 (API 22) and I've also installed other SDK packages that were required. When i create the project I compile and target with API 22 and the rest of the setting i leave as default. I've seen somewhat similar questions regarding this but the solutions have unfortunately not worked out for me.
Any help or thoughts is greatly appreciated!
If you can then install Android Studio which is the officially supported IDE for android sdk.
You won't have to download libraries jar and instead use the repositories in the maven servers.
Alternative :::
In project.properties file remove appcompat_v7 reference line. Then remove all the error lines that you get in some files like manifest.xml, values folder files, and may be in some java files.
Since appcompat_v7 is not there then its all references should be deleted.
In activity files extend it to Activity.

Problems importing the android support library with resources

As soon as I finish importing the android support library project into my workspace (I am using eclipse ide), I receive this error message:
Could not not write to file: C:\Program Files\extras\android\support\v7\appcompat\bin
The library project appears in my workspace, however if i try a clean build:
Errors occurred during the build. Errors running builder 'Android
Package Builder' on project 'android-support-v7-appcompat'. Resource
'/android-support-v7-appcompat/bin' does not exist.
Here is the stack trace:
[2013-12-17 18:11:20 - android-support-v7-appcompat] Android requires
compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use
Android Tools > Fix Project Properties.
The error log also states that bin folder does not exist/cannot be written to.
Here are things I have tried so far and failed:
1. Clean build
2. Install then re install
3. Fix android properties.
I have not used any of the API from the support library.
Open the project properties in Eclipse. Choose Java Compiler and make sure the Compiler Compliance level is set to 1.5 or 1.6.

Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException

I am getting following exception when I am trying to run my Android project.
Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException
Currently now I am using ADT version 22.3. My project target is API level-15. I tried to add Support library in Android tools, but problem not resolved.
the key is to set target=android-19 from project.properties and android:targetSdkVersion="19" same to 19. This has worked for me.
Its a big mess... Following way did the trick for me...
Right click your project in eclipse -> Android Tools -> Add Support Library
Then click Accept License and click install.
I had the same problem and I used these methods
1- Downgrading to Android SDK build tools 18.1.1
2- Adding the support library. (if it already there, try removing it and adding it again, Right click on project -> Android tools -> Add support library)
you can follow the detailed instructions here
http://techlovejump.in/2013/11/how-to-solve-unable-to-execute-dex-java-nio-bufferoverflowexception-check-the-eclipse-log-for-stack-trace/
Link above is broken but provides valid solution. Updated link: http://techlovejump.in/how-to-solve-unable-to-execute-dex-java-nio-bufferoverflowexception-check-the-eclipse-log-for-stack-trace/
Is this the same problem as Android dex gives a BufferOverflowException when building ? Updating to the 19.0.1 Build-tools (as described in the linked post) fixed this problem for me.
Browse through your eclipse Folder->
Open Eclipse Folder
Open eclipse.ini
Change -Xms40m And -Xmx384m TO -Xms512m And -Xmx512m
Click Save
No need to downgrade.
You can fix the error by editing the manifest file or project properties. Add following line.
sdk.build.tools=18.1.1
replace 18.1.1 with your targetsdk in manifest.
Step by step detail on :- http://techlovejump.in/2013/11/how-to-solve-unable-to-execute-dex-java-nio-bufferoverflowexception-check-the-eclipse-log-for-stack-trace/
I Update the project.properties file. I put sdk.build.tools=19.0.1 in property file. And set the minimum SDK version to 14
it happened to me when my emulator had set a high Ram value, i changed the emulator RAM value to 768 and then it worked
I've dealt with this problem when using Sherlock ActionBar library in my project.
You could do the following step, it's work for me.
Right click to your project, select properties.
A dialog will show up, select 'Java build path' on the left menu.
Remove 'Android dependencies' and 'Android private libraries' on the right panel then click OK
Clean your project (select menu Project --> Clean)
Right click your project, select Android Tools -> Fix project properties
Clean project once again.
Restart your computer
Open eclipse and Export apk
Hope that will help you.
I was having redundant libraries in my IDE that was causing an issue none of the other solution worked for me

R cannot be resolved to a variable. Eclipse error

Good morning.
I am creating a "Android Application Project" and I get an error "R can not be resolved to a variable". The error I get nothing and create the blueprint (the "Hello World") without adding any thing more (the basic example).
Thank you.
PS: Platform SDK: API 17; Android SDK Tools: 22.0.1, Build-Android SDK Tools: 17.
As stated here:
After updating to SDK Tools to rev. 22 for the first time, you may need to relaunch Android SDK Manager again and install a new item: Android SDK Build-tools.
After installing this, clean your projects and rebuild.
'R' isn't generated if there are any errors in your XML files. So check all your XML files. Check for errors in naming the XML files. No capital letters etc.
If you're using Eclipse, it helps if you delete your gen folder and add it using Project > Properties > Java Build Path > Source tab > Add Source > Select gen and then Clean and Build your project

AAPT.exe crashed after added the Aursama kernal in Project

I am trying to integrate Aurasma kernal with my android application. I followed the instructions as given in the http://www.aurasma.com/partners/support/Aurasma%20Kernel%20Guidelines.pdf. The build fails with aapt.exe crashing in the pre-compilation phase.
The manifest file has the settings as - minSDKversion: 8 targetSDKversion: 14
Following are the libraries in my application:
android-support-v4.jar
facebookSDK.jar
FlurryAgent.jar
httpclient-4.1.2.jar
httpcore-4.1.2.jar
httpmime-4.1.2.jar
apache-mime4j-core-0.7.jar
myttjson-1.7.1.jar
scribe-1.1.0.jar
trace.jar
I found httpmime-4.11.jar and apache-mime4j-0.6.1.jar in aurasma kernal build path. Because of this, I got an error that there are multiple dex files. I removed these jars from my application's build path. The issue of multiple dex files is resolved, but Aapt crash remains.
Assuming that the problem could be limited to the Windows version of Aapt, I tried it on a Mac. After nearly the same time and steps, Aapt terminated with an error code 139.
i have changed the Windows > Preference > Andriod > Build > Output to Normal and Verbose but the Aapt crash remains.
Please help me to resolve this issue
i have resolved the problem,in my project style.xml for some of the styles definitions have android:id , this causes the aapt crash, after i removed this its working fine.

Categories

Resources