Gradle Java heap space 🤖 Android

Gradle: Expiring Daemon because JVM heap space is exhausted / java.lang.OutOfMemoryError: Java heap space during build

The Gradle daemon (or Kotlin daemon) ran out of memory compiling or dexing the project.

Seen on: Android

Meaning

Large projects, many modules, R8 and Kotlin compilation need more heap than the default. Set org.gradle.jvmargs in gradle.properties; CI machines with little RAM may need fewer parallel workers.

Common causes

  • Default -Xmx too small for the project
  • R8/dexing of a large app
  • Kotlin daemon memory
  • CI runner with limited RAM

⚡ Quick fix

  1. Raise org.gradle.jvmargs (e.g. -Xmx4g)
  2. Set kotlin.daemon.jvmargs
  3. Limit parallel workers on small CI machines

Detailed fix by platform

Gradle

  1. kotlin
    # gradle.properties
    org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8
    kotlin.daemon.jvmargs=-Xmx2g
    org.gradle.workers.max=2

How to diagnose

  1. Memory — Machine RAM vs -Xmx
  2. Task — Which task fails (R8, kotlin, dex)?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.