80

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?

gprathour
  • 14,813
  • 5
  • 66
  • 90
AndroidPlaya
  • 803
  • 1
  • 7
  • 4
  • Can you please post the lines that you added to eclipse? – CRM May 10 '11 at 00:01
  • -startup plugins/org.eclipse.equinox.launcher_1.1.0.v20100507.jar --launcher.library plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.1.R36x_v20100810 -product org.eclipse.epp.package.java.product --launcher.defaultAction openFile --launcher.XXMaxPermSize 512M -showsplash org.eclipse.platform --launcher.XXMaxPermSize 512m --launcher.defaultAction openFile -vmargs -Dosgi.requiredJavaVersion=1.5 -Xms512m -Xmx512m – AndroidPlaya May 10 '11 at 05:12
  • i too just have the entries -data @noDefault in my init: I've tried adding various code including -Xms512m -Xmx512m and -vmargs -Xms512m -Xmx512m in various permutions with the these two lines. also there are suggestions for adding about 20 more lines of code which I've also tried. someone needs to post the COMPLETE lines of code needed in the exclipse.ini, from top to bottom, and whether any file paths in the added code have to be customized, which will be different for various configurations – Androidcoder Jun 07 '13 at 16:33
  • I've also tried launching from command line with eclipse -vmargs -Xms512m -Xmx512m which hasn't worked – Androidcoder Jun 07 '13 at 16:35

5 Answers5

209

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

Blundell
  • 75,855
  • 30
  • 208
  • 233
JohnnyLambada
  • 12,700
  • 11
  • 57
  • 61
  • 8
    [This page](http://wiki.eclipse.org/Eclipse.ini#-vm_value:_Mac_OS_X_Example) describes how to find eclipse.ini on mac. – JohnnyLambada Sep 10 '12 at 18:49
  • 7
    In Windows it sits right alongside `eclipse.exe`, wherever you put it. – Cheezmeister Oct 13 '12 at 22:45
  • 1
    The only entries I have are -data @noDefault Please advise – Roy Hinkley Nov 21 '12 at 17:03
  • @JohnnyLambada Hi Johny I have added 7mb jar File and have modified the xms variable to 1024m both. But Now I am getting this error Conversion to Dalvik format failed with error 1 – Gaurav Arora Nov 29 '12 at 07:18
  • @GauravArora - will it compile with ant? Are you using the very latest sdk? It has some improvements for dex -- you may be able to get away with compiling with ant and relying on dex to use the already-compiled dex object within eclipse. From the [release notes](http://developer.android.com/tools/sdk/tools-notes.html) _Improved the build time by pre-dexing libraries (both JAR files and library projects)._ – JohnnyLambada Nov 29 '12 at 17:18
  • Could you explain the difference between xms and xmx? – Jacob Mar 19 '14 at 19:33
  • 1
    The flag Xmx specifies maximum memory allocation pool for a Java Virtual Machine (JVM), while Xms is specifies the initial memory allocation pool according to [this SO answer.](http://stackoverflow.com/questions/14763079/what-are-the-xms-and-xmx-parameters-when-starting-jvms) – JohnnyLambada Mar 19 '14 at 22:02
  • @Cheezmeister this is totally useless answer, it is not solving my problem, – Sandeep Londhe Aug 26 '15 at 12:47
20

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.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
Mihir Shah
  • 996
  • 10
  • 19
  • 5
    Unchecking the library from 'Order and Export' results in 'ClassNotFoundException' being thrown when a class from that library is accessed from the code. The library(s) should be exported. – Vaishak Nair Nov 20 '14 at 04:23
  • Yes thats right, I am getting the Java Heap Error, when I Unchecked all the library, it executes but application is crashing on the device, please help me.. – AK Joshi Sep 04 '15 at 12:04
0

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 .

GOLDEE
  • 2,318
  • 3
  • 25
  • 49
  • I face same issue, I also tried, memory size changes. But problem not resolved. Finally, I did, Project Explorer -> right click -> Maven -> update project. My problem resolved. Once i took latest checkout, I should do Maven update. But I did mistake. – Sun Aug 12 '14 at 12:48
  • @Ravi how do you solve the error, let me know as well. – Sandeep Londhe Aug 26 '15 at 12:50
0

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.

noman404
  • 928
  • 1
  • 8
  • 23
-1

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.

Alexander Ukhov
  • 458
  • 6
  • 10