Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Gradle build stops with 'Could not dispatch a message to the daemon'

ErrorCould not dispatch a message to the daemon

Short answer

The Gradle client lost contact with its background daemon, so the daemon died or was stopped. Read the daemon log in the Gradle user home to see why. Then stop all daemons and retry. If memory ran short, give the daemon more heap or free system memory.

  • Applies to Gradle 8.x, Gradle 9.x, Android Gradle Plugin 8.x, JDK 17
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List the daemons and open the log of the one that died. Daemon logs sit in the Gradle user home, one file per process.

    ./gradlew --status
    ls ~/.gradle/daemon/*/
  2. 2Match what you see, then jump to its fix

    1. 1The first build after a crash, a sleep or a Gradle upgrade fails, and --status shows an old daemonA stale or broken daemon is being reusedFix
    2. 2The daemon log ends without an error, the build died during a heavy step, and other apps were using a lot of RAMThe daemon was stopped because the machine ran low on memoryFix
    3. 3--status lists several daemons, and the IDE's Gradle JDK differs from JAVA_HOMEGradle and the IDE use different JDKs, so daemons clashFix

What does the error look like?

  • Could not dispatch a message to the daemon

Cause 1 of 3

A stale or broken daemon is being reused

1Check

Gradle's documentation says that if builds behave unexpectedly, stopping the daemon and trying again is the first move. --stop ends daemons of the same Gradle version.

./gradlew --status

2Fix

Stop the daemons and run the build again. A fresh daemon starts on its own.

./gradlew --stop
./gradlew assembleDebug

3Verify

The build runs, and --status shows a new daemon.

./gradlew --status

Confirmed by docs.gradle.org

Did this fix it?

Cause 2 of 3

The daemon was stopped because the machine ran low on memory

1Check

The daemon documentation says daemons stop when available system memory is low. The daemon's own heap defaults to 512 MB (org.gradle.jvmargs), which is small for an Android build.

grep -n "jvmargs" gradle.properties ~/.gradle/gradle.properties

2Fix

Close memory-heavy apps, and set an explicit heap for the daemon in gradle.properties.

# gradle.properties
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g

3Verify

Stop the old daemon so the new setting applies, then build again.

./gradlew --stop
./gradlew assembleDebug

Confirmed by docs.gradle.org

Did this fix it?

Cause 3 of 3

Gradle and the IDE use different JDKs, so daemons clash

1Check

The daemon documentation warns that when the Gradle JDK and JAVA_HOME differ, several daemons get spawned. It says to align the Java versions across the environment, build script toolchains and the IDE.

echo $JAVA_HOME
./gradlew --version

2Fix

Choose one JDK. Set JAVA_HOME to it and select the same JDK in the IDE's Gradle settings, then stop the daemons.

export JAVA_HOME=/path/to/your/jdk
./gradlew --stop

3Verify

Run the build from the terminal and from the IDE; --status should show one daemon.

./gradlew --status

Confirmed by docs.gradle.org

Did this fix it?

How do I stop it coming back?

  • Set org.gradle.jvmargs explicitly instead of relying on the default heap.
  • Run ./gradlew --stop after changing the JDK or editing gradle.properties.
  • Keep one JDK for the terminal and the IDE.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Android Studio cannot pair the phone over Wi-Fi

The Pair devices over Wi-Fi dialog lists no device

Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.