android memory_error ai_generated true

java.lang.OutOfMemoryError: GC overhead limit exceeded during Gradle build

ID: android/gradle-oom

Also available as: JSON · Markdown
88%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
8 active

Root Cause

Gradle build runs out of memory. Project too large, too many modules, or JVM heap too small.

generic

Workarounds

  1. 90% success Increase Gradle JVM heap to reasonable size (4-8GB)
    In gradle.properties: org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=512m

    Sources: https://developer.android.com/build/

  2. 85% success Enable Gradle configuration cache to reduce memory per build
    org.gradle.configuration-cache=true  # in gradle.properties
  3. 78% success Use modularization to reduce per-module build scope

Dead Ends

Common approaches that don't work:

  1. Set org.gradle.jvmargs=-Xmx16g as first attempt 60% fail

    Excessive heap hides the real problem (inefficient build) and slows down GC pauses

  2. Disable Gradle daemon to reduce memory usage 72% fail

    Daemon keeps JVM warm for faster builds. Disabling it makes every build slower.