Conversion to Dalvik format failed: Unable to execute dex: Java heap space

JavaAndroidEclipse

Java Problem Overview


I have added a 2.45mb jar file to my Android eclipse project and now I continue to get "Conversion to Dalvik format failed: Unable to execute dex: Java heap space" no matter what I do.

I have researched online, and was informed to update my eclipse.ini to increase my Java VM heapsizes. I have done this for all the values in eclipse.ini and I continue to get the build error.

Any ideas?

Java Solutions


Solution 1 - Java

Modify the -XmsAm and -XmxBm paremeters in eclipse.ini so that they are large enough. The default is -Xms40m -Xmx384m. Try changing them both to -Xms512m -Xmx512m and restart eclipse to see if that helps. If not, continue to increase the values and restart eclipse until either one of two things happens:

  1. Your build completes.
  2. Eclipse won't restart because you don't have enough memory.

eclipse.ini is located at /etc/eclipse.ini in Ubuntu (assuming you installed Eclipse from the Ubuntu repositories).

For MAC please see:

>Finding eclipse.ini is a wee bit tricky. To locate it, right-click on the Eclipse Application icon and select "Show Package Contents", then double-click on the "Contents" folder and then double-click on the "MacOS" folder, the home of eclipse.ini

https://confluence.sakaiproject.org/pages/viewpage.action?pageId=61341742

Solution 2 - Java

Sometimes checking the .jar library in project properties also causes this problem. In that case, try the following:

Right click your project. 
Go to Properties -> Java Build Path -> Order and Export.
Uncheck the check box against your included library. 
Press OK and run the project.

On doing this Eclipse will take only the classes which are needed in the code, from the jar instead of storing all the classes from the jar.

Solution 3 - Java

All above answers are perfect , but you can try one more thing and that is fast and easy , close all your unnecessary open projects in Eclipse workspace and then Restart Eclipse .

You can also increase the -XmsAm and -XmxBm paremeters in eclipse.ini .

Solution 4 - Java

Go to your project properties and remove your added libraries from Java Build Path hit ok, then again re add them. I also faced this problem.By doing this I solved this issue.

Solution 5 - Java

Important addition:

The solution didn't work on my Windows (probably memory allocation issues), but did well on a Linux on same machine. So installation of another OS would help you or Windows re-installation.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndroidPlayaView Question on Stackoverflow
Solution 1 - JavaJohnnyLambadaView Answer on Stackoverflow
Solution 2 - JavaMihir ShahView Answer on Stackoverflow
Solution 3 - JavaGOLDEEView Answer on Stackoverflow
Solution 4 - Javanoman404View Answer on Stackoverflow
Solution 5 - JavaAlexander UkhovView Answer on Stackoverflow