Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OutOfMemoryError when compiling my android app with gradle

I'm trying to build my app via gradle and I'm currently having this issue after running a ./gradlew build:

:myApp:compileDebug   The system is out of resources. Consult the following stack trace for details. java.lang.OutOfMemoryError: Java heap space     at com.sun.tools.javac.util.Position$LineMapImpl.build(Position.java:139)     at com.sun.tools.javac.util.Position.makeLineMap(Position.java:63)     at com.sun.tools.javadoc.DocCommentScanner.getLineMap(DocCommentScanner.java:438)     at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:512)     at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:550)     at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:804)     at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)     at com.sun.tools.javac.main.Main.compile(Main.java:353)     at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:115)     at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:40)     at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:33)     at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:95)     at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:48)     at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:34)     at org.gradle.api.internal.tasks.compile.DelegatingJavaCompiler.execute(DelegatingJavaCompiler.java:29)     at org.gradle.api.internal.tasks.compile.DelegatingJavaCompiler.execute(DelegatingJavaCompiler.java:20)     at org.gradle.api.internal.tasks.compile.IncrementalJavaCompilerSupport.execute(IncrementalJavaCompilerSupport.java:33)     at org.gradle.api.internal.tasks.compile.IncrementalJavaCompilerSupport.execute(IncrementalJavaCompilerSupport.java:24)     at org.gradle.api.tasks.compile.Compile.compile(Compile.java:68)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     at java.lang.reflect.Method.invoke(Method.java:597)     at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)     at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)     at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047)     at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877)     at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:216)     at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:122)     at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)     at org.gradle.api.tasks.compile.JavaCompile_Decorated.invokeMethod(Unknown Source)     at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source) :myApp:compileDebug FAILED 

Any idea?

like image 978
Romain Piel Avatar asked Jul 03 '13 12:07

Romain Piel


People also ask

How do you fix OutOfMemoryError?

1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.

What went wrong out of memory Java heap space gradle?

OutOfMemoryError issues occur either in the compile phase of your project or the test phase of your project while building your Gradle project. If the error occurs during compilation, you must increase heap size thus according to your system capacity and use the following lines of code in Linux and Windows.


2 Answers

I think I fixed it. I got the solution from this post. i.e:

replacing in gradlew:

GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 

by

GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\" \"-Xmx1024m\" \"-Xms256m\" \"-XX:MaxPermSize=1024m\"" 
like image 143
Romain Piel Avatar answered Sep 19 '22 16:09

Romain Piel


In my project there was a gradle.properties file with these lines:

# Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 

I uncommented the last line, and that worked.

like image 24
dfrankow Avatar answered Sep 19 '22 16:09

dfrankow