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
- Raise org.gradle.jvmargs (e.g. -Xmx4g)
- Set kotlin.daemon.jvmargs
- Limit parallel workers on small CI machines
Detailed fix by platform
Gradle
- 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
- Memory — Machine RAM vs -Xmx
- 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:
Similar errors
- 0xC0000005 The application was unable to start correctly (0xc0000005) / Exception code 0xc0000005 access violation
- 10000 wrangler / Cloudflare API: Authentication error [code: 10000]
- AADSTS70021 AADSTS70021: No matching federated identity record found for presented assertion (GitHub Actions / workload identity)
Most viewed in Android
Other ways to find it
🧠 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026