java.lang.OutOfMemoryError appears during build of android 2.1 on Mac OS X 10.6.8

java.lang.OutOfMemoryError appears during build of android 2.1 on Mac OS X 10.6.8 … here is a solution to the problem.

java.lang.OutOfMemoryError appears during build of android 2.1 on Mac OS X 10.6.8

This is a build issue I’m struggling to solve. I’m trying to build Android 1.5 on Mac OS X 10.6.8 with jdk 2.1. The “make” command ran for a while, and finally, it said:

The system is out of resources.
Consult the following stack trace for details.
java.lang.OutOfMemoryError: Java heap space
    at com.sun.tools.javac.code.Scope.dble(Scope.java:150)
    at com.sun.tools.javac.code.Scope.enter(Scope.java:185)
    at com.sun.tools.javac.comp.MemberEnter.importAll(MemberEnter.java:129)
    at com.sun.tools.javac.comp.MemberEnter.visitTopLevel(MemberEnter.java:504)
    at com.sun.tools.javac.tree.Tree$TopLevel.accept(Tree.java:382)
    at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:383)
    at com.sun.tools.javac.comp.MemberEnter.complete(MemberEnter.java:778)
    at com.sun.tools.javac.code.Symbol.complete(Symbol.java:355)
    at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:612)
    at com.sun.tools.javac.comp.Enter.complete(Enter.java:463)
    at com.sun.tools.javac.comp.Enter.main(Enter.java:441)
    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:404)
    at com.sun.tools.javac.main.Main.compile(Main.java:592)
    at com.sun.tools.javac.main.Main.compile(Main.java:544)
    at com.sun.tools.javac.Main.compile(Main.java:92)
    at util.build.JavacBuildStep.build(JavacBuildStep.java:69)
    at util.build.BuildDalvikSuite.handleTests(BuildDalvikSuite.java:504)
    at util.build.BuildDalvikSuite.compose(BuildDalvikSuite.java:170)
    at util.build.BuildDalvikSuite.main(BuildDalvikSuite.java:136)
main javac dalvik-cts-buildutil build step failed
make: *** [out/host/darwin-x86/obj/EXECUTABLES/vm-tests_intermediates/tests] Error 1

It seems that the Java heap size is not enough. I googled this issue and it gave me several links such as:

These pages mainly suggest adding the “-Xmx” option to JVM Options. I tried the following:
Added this column in /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0-leopard/Resources/Info.plist

VMOptions
-Xms1024M -Xmx2048M

(I also tried setting up VMOptions.x86_64 instead of VMOptions).

After another link (osdir.com/ml/android-platform/2010-06/msg00097.html), I also changed the following line in the build/core/definitions.mk file in the android build directory.

$(hide) java -Xmx512M -jar $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar \

to

$(hide) java -Xmx2048M -jar $(HOST_OUT_JAVA_LIBRARIES)/proguard-4.0.1.jar \

None of the above helped. I have a few questions :

  • Whether it can be changed system-wide
    Java heap size on Mac OS X, is this the right way to go? If so, are the changes I made in the Info.plist file achievable?
  • Or I have to change the heap size
    Built specifically for Android? If so, what should I do?

Edit

Just an update: I tried building android 3.1 with jdk 1.6 and the build went smoothly. (even if the “-Xmx” option is not set for JDK 1.6). I still don’t know what went wrong when building 2.1 with jdk 1.5.

Solution

Sometimes OutOfMemoryError is not due to insufficient Heap. Try adding PermGen:

-XX:PermSize=40m
-XX:MaxPermSize=240m

Sometimes it is also caused by the poor size of Young and Ternured. Still others should perform Full GC for a long time and have a low percentage of collection.

Greeting.

Related Problems and Solutions