Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 2.2, Gradle build fails with java.lang.OutOfMemoryError: unable to create new native thread

I just upgraded to Android Studio 2.2 and I can no longer build my project because the Gradle build always fails with multiple java.lang.OutOfMemoryError: unable to create new native thread

From my research, it seems this could have more to do with my operating system (OSX El Capitan) than with Gradle itself. However, I have attempted several workarounds with no success.

My studio.vmoptions file looks like this:

# custom Android Studio VM options, see http://tools.android.com/tech-docs/configuration
-Xms128m
-Xmx750m
-XX:MaxPermSize=512m
-XX:ReservedCodeCacheSize=96m
-XX:+UseCompressedOops
-XX:+HeapDumpOnOutOfMemoryError

ulimit -a gives me the following:

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 256
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 709
virtual memory          (kbytes, -v) unlimited

I've tried increasing my max user processes to no avail. Is anyone else having this issue? My current JDK is 1.8.0_102

like image 373
mylovemhz Avatar asked Sep 20 '16 17:09

mylovemhz


People also ask

What went wrong unable to create new native thread?

OutOfMemoryError: Unable to create new native thread means that the Java application has hit the limit of how many Threads it can launch.

How many threads the OS will allow your JVM to use?

Each JVM server can have a maximum of 256 threads to run Java applications.

What is native thread in Java?

"Native threads" refers to a in which the Java virtual machine creates and manages Java threads using the operating system threads library - named libthread on UnixWare - and each Java thread is mapped to one threads library thread.


1 Answers

I have the same issue with my project which can be built without problem before upgrading.

Switched back to gradle 2.1.3 from 2.2.0 fixed the problem.

buildscript {
    ...
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
    }
}
like image 60
Ray Chang Avatar answered Sep 27 '22 19:09

Ray Chang