Unable to execute dex: GC overhead limit exceeded in Eclipse

JavaAndroidOut of-MemoryDalvik

Java Problem Overview


When I downloaded the Git project OsmAnd and went to compile it, Eclipse returned these errors:

[Dex Loader] Unable to execute dex: GC overhead limit exceeded
[OsmAnd]     Conversion to Dalvik format failed: 
             Unable to execute dex: GC overhead limit exceeded

Google and Stackoverflow said that I must change -Xms40m -Xmx384m in eclipse.ini. Conversion to Dalvik format failed: Unable to execute dex: Java heap space.
I cleaned project and restarted Eclipse, but it did not help.

I found this link: Tips for Android developer: “Conversion to Dalvik format failed: Unable to execute dex: null” But I do not know which .jar from my project to change the input in. If anyone can help, I can send the project to them.

Java Solutions


Solution 1 - Java

It can be fixed by changing the VM values in Eclipse.ini. Set the values to 512 and 1024 as below:

openFile
--launcher.XXMaxPermSize
512M
-showsplash
org.eclipse.platform
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms512m
-Xmx1024m

The changed area in image enter image description here

Solution 2 - Java

For me following steps worked

1) Open eclipse.ini file
2)changed
-Xms40m
-Xmx512m
to 
-Xms512m
-Xmx1024m

3)Restart eclipse

See here

Solution 3 - Java

eclipse.ini look like this.

-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20140116-2212
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.6
-XX:MaxPermSize=256m
-Xms40m
-Xmx512m
-Xmx1024m

Solution 4 - Java

Let me assume this problem caused due to the Android XML, because of very frequently you're opening it

These following two issues on StackOverFlow are realted with each other:

Every time I click on an Android XML file in Eclipse, it loads data for all API versions

and

Unable to execute dex: GC overhead limit exceeded

I found one more solution to resolve this problem other than increasing the VM values or downgrading to an older ADT version (22.6.2 or 23.2)

Note:

Some of the older ADT versions which won't load the XML each and every time you open so there is no memory overflow to cause this GC overhead limit exceeded as discussed on the first thread

Solution:

At the bottom of the eclipse there will be Trash can symbol which states Run Garbage Collector. Whenever you close an XML file of android don't forget to just click on the Trash Can or Run Garbage Collector to release memory. This way you can protect the workspace from crashing this kind of error :D

This could be an ultimate solution because you can't increase the VM value beyond your RAM limit if you very frequently open your android XML especially if you do lot of UI works like me :P

I hope this would help everyone who will come to this thread :)

Keep Calm and Code On

Solution 5 - Java

After 12 hours with this error and no success with changing the eclipse.ini file I finally found the correct solution. In my environment variables there was a variable named "_JAVA_OPTIONS" containing the value "-Xmx512M". Changing this value to the same value as in eclipse.ini (-Xmx4096M) I was once again able to export my project to an APK file.

Solution 6 - Java

I DO NOT know the reason behind this work-around, but it works for me all the time when all of the above don't.

Do not start eclipse from a short-cut or a link. Always open it from the eclipse.exe in your eclipse folder, the very folder which holds the eclipse.ini

Note - I tried only for linux.

Solution 7 - Java

To avoid this annoyable message, i had to change my configuration as follows:

-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20120913-

144807
-product
com.android.ide.eclipse.adt.package.adtproduct
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
1024m
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.6
-XX:MaxPermSize=256m
-Xms512m
-Xmx1024m

based on the answer marked as correct, changing

-XX:MaxPermSize=256m
-Xms512m
-Xmx1024m

and:

--launcher.XXMaxPermSize
1024m

Solution 8 - Java

1) Open eclipse.ini file
2)change
-Xms40m
-Xmx512m
to 
-Xms512m
-Xmx1024m
3)Restart eclipse

The same eclipse.ini file will be located in Eclipse in this root path of eclipse itself like:

C:\Users\username\Downloads\adt-bundle-windows-x86_64-20140702\eclipse\eclipse.ini

The same file will be located in android studio project:-

C:\Users\username\AppData\Local\Android\sdk\tools\lib\monitor-x86_64\monitor(Type:Configuration settings)

Solution 9 - Java

If these answers don't work (They didn't for me) then try this:

  1. Make a copy of your .metadata folder in your workspace.

  2. Delete your .metadata directory AFTER MAKING A COPY

  3. Open Eclipse and close Eclipse.

  4. Copy your plugins folder from your old .metadata to your new .metadata

  5. Import all the projects back into your workspace

  6. Keep Calm and Code On!

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
QuestionDavyJonesUAView Question on Stackoverflow
Solution 1 - Javauser1457659View Answer on Stackoverflow
Solution 2 - JavaSunil Kumar SahooView Answer on Stackoverflow
Solution 3 - JavaRoadiesView Answer on Stackoverflow
Solution 4 - JavaAkbarshaView Answer on Stackoverflow
Solution 5 - JavaViktorView Answer on Stackoverflow
Solution 6 - JavaAtul O HolicView Answer on Stackoverflow
Solution 7 - JavaJorgesysView Answer on Stackoverflow
Solution 8 - Javaanand krishView Answer on Stackoverflow
Solution 9 - JavatricknologyView Answer on Stackoverflow