5 Dec 2015

Seeing java.lang.OutOfMemoryError : GC overhead limit when compiling

You are most likely exhausting the heap size especially during compilation. Try to add inside this setting in your app/build.gradle:

android {
   .
   .
   .
   dexOptions {
     javaMaxHeapSize "4g"
   }
}

You can also reduce the build time too by setting incremental to be true:

android {
   dexOptions { 
      incremental true
      javaMaxHeapSize "4g"
   }
}

Still not working? Try to increase the heap size of Android Studio.
  1. Quit Android Studio.
  2. Create or edit a studio.vmoptions file.
    • On Mac, this file should be in ~/Library/Preferences/AndroidStudio/studio.vmoptions.
    • On Windows, it should be in %USERPROFILE%\.AndroidStudio\studio[64].exe.vmoptions.
    Increase the maximum memory to 2 Gb and max heap size of 1 Gb.
     -Xmx2048m
     -XX:MaxPermSize=1024m`
    
  3. Start Android Studio.

No comments:

Post a Comment