Android Studio 2.2, Gradle build fails with java.l

2019-04-08 17:49发布

问题:

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

回答1:

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'
    }
}


回答2:

In case someone runs into the same wall I did, you may try disabling Instant Run. I had to take these steps to build successfully: - upgrade to gradle 2.2.3 when prompted - disable Instant Run in AS preferences - go back to gradle 2.1.3 in build.gradle



回答3:

go back to gradle 2.1.3 in build.gradle file.