How do I fix java.lang.OutOfMemoryError: Java heap space
when compiling my Android project?
I get this after I upgraded to version 1 of Android Studio.
i'm using Windows OS. I solved this by updating _JAVA_OPTIONS to '-Xmx1024m'
click to see snapshot
The answers above are for gradle builds (or the general -Xmx). In case someone gets here for a non-gradle project, I solved the issue by increasing the maximum heap size of DEX in android studio settings => Build, Execution, Deployment => Compiler => Android Compilers
This issue also may happen with usage of the debug build of Proguard. To solve it change minifyEnabled
and shrinkResources
to false.
android {
...
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
debug {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
} }
This is old, but just add this to the build file
dexOptions {
javaMaxHeapSize "2g"
}
I had a similar issue on Android Studio 2.3.3. APK packaging would fail saying Java heap space
when building from Android Studio and trying to process a 300MB .so library. In my case two things were needed to fix it. Your build.gradle
should contain something like that:
android {
dexOptions {
javaMaxHeapSize "4G"
}
}
At the root of your project you need to have a file named gradle.properties
containing the following:
# That's needed for java to be able the create the APK with our 300MB native library
# Basically we grant java a 4GB heap.
org.gradle.jvmargs=-Xmx4608m
you have changed the wrong arguments, you should increase the size on -XX:MaxPermSize=512M to -XX:MaxPermSize=2048M or so :) because the android emulator uses a lot of RAM.