3

I am so tired of this java heap space error on my eclipse whenever I build my android application. I add 9 libraries to my android application. (Right click on project name -> Properties -> Android -> Add library).

In some forums, I find people asking to make changes in eclipse.ini file and some saying to add user library and add jars to it. And add user library to my app.

I have changed my MaxPermSize to 1024 in eclipse.ini. It didnt help

When I add user library to my app, my app is not able to recognise app_compat_v7.jar. It throws error on styles file where I use Theme.Appcompat.Light

May I know where I am going wrong ? Any help will be appreciated.

Spring Breaker
  • 8,233
  • 3
  • 36
  • 60
Riny
  • 159
  • 1
  • 6
  • 17
  • 1
    Have run into that error several times, and unchecking Project > Build Automatically followed by manually building it (and then signing the app, where the error usually occurs for me) did the trick. As for the style errors, try going to Show View > Problems, highlight the X's for the styles file only, and then delete the problems, followed by cleaning the project. Any time I change the styles.xml file it throws the same issues based on it not recognizing the compatibility/normal packages, but ends up running fine. – Cruceo Apr 21 '14 at 20:12
  • did u got any idea .How to fix this issue ?? – abh22ishek Aug 18 '14 at 11:13
  • 1
    See this at the bottom of your eclipse http://prntscr.com/4e90ox In the screenshot given, the max heap space allocated is 211M and 118M has been used. I made changes to eclipse.ini file which looks like this http://prntscr.com/4e92de – Riny Aug 19 '14 at 05:48

1 Answers1

4

Try the following:

Right click your project. Go to Properties -> Java Build Path -> Order and Export.

And

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.

And also see this question.

Second Technique

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

Community
  • 1
  • 1
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
  • I am trying to use Google-play-service-lib in my project when I check checkbox from Properties -> Java Build Path ->Order and Export I am getting error "unable to execute dex java heap space java heap space in eclipse"and if I unchecked and added .jar files of google play services libs I am getting an error "java.lang.NoClassDefFoundError:Lcom/google/android/gms/common/GooglePlayServicesUtil;" what to do? please help me I am trying to fix this error last 2 days. Also, change setting of eclipse.ini :( but not luck – Mohini Jul 29 '15 at 13:30
  • Mohini , Keep increasing the Xms and Xmx values until it either works or you run out of physical memory. and first try by removing all associated libraries and jar. and then restart eclipse and reset it from start. – Zar E Ahmer Jul 29 '15 at 13:56
  • I set values -Xms4096M -Xmx4096M still getting problem. And If I am removing all associated libraries and jar project getting errors – Mohini Jul 29 '15 at 14:13
  • Have you restart after saving in eclipse.ini – Zar E Ahmer Jul 29 '15 at 14:20
  • yes I restarted -Dosgi.requiredJavaVersion=1.6 --launcher.XXMaxPermSize 4096M -XX:MaxPermSize=4096M -Xms4096M -Xmx4096M – Mohini Jul 29 '15 at 14:21
  • you are using eclipse or android studio – Zar E Ahmer Jul 29 '15 at 14:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/84583/discussion-between-mohini-and-nepster). – Mohini Jul 29 '15 at 14:24