Tag Archives: GC

Android 빌드 시 OutOfMemoryError 해결 방법

android_studio

안드로이드 프로젝트가 커지게 되면서 빌드 시 메모리가 부족하다는 오류를 만나게 되는 경우가 있습니다. 오류 메시지는 대략 다음과 같은 형태를 띄고 있습니다.

Exception in thread "pool-1-thread-11" java.lang.OutOfMemoryError: GC overhead limit exceeded
Exception in thread "pool-1-thread-10" java.lang.OutOfMemoryError: GC overhead limit exceeded
Exception in thread "pool-1-thread-12" java.lang.OutOfMemoryError: GC overhead limit exceeded

UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: GC overhead limit exceeded

말 그대로 빌드시에 필요로하는 메모리가 부족한 경우인데요 힙사이즈를 적당히 늘려주면 빌드가 성공하게 됩니다. 힙사이즈의 설정은 프로젝트의 build.gradle 파일에 해주시면 됩니다.

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

저의 경우에는 4G정도로 설정해 주었더니 빌드가 성공하였습니다.  만약이지만 위와 같은 처리후에 다음과 같은 오류를 만나는 경우가 있을 수 있습니다.

Unable to execute dex: Cannot merge new index 65662 into a non-jumbo instruction!
Conversion to Dalvik format failed: Unable to execute dex: Cannot merge new index 65662 into a non-jumbo instruction

이런 경우 jumboMode를 켜주시면 해결될 것입니다. ADT 21 이후로 사용가능한 플래그입니다.

android {
  dexOptions {
    ...
    jumboMode = true
    javaMaxHeapSize "4g"
  }
}

참고 : http://stackoverflow.com/questions/23688116/how-do-you-adjust-jvm-args-for-dex-memory-in-gradle