Gradle build stops with 'Could not dispatch a message to the daemon'
Could not dispatch a message to the daemonShort 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.
Fix it fast
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/*/2Match what you see, then jump to its fix
- 1
The 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
The 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
--status lists several daemons, and the IDE's Gradle JDK differs from JAVA_HOMEGradle and the IDE use different JDKs, so daemons clashFix
- 1
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 --status2Fix
Stop the daemons and run the build again. A fresh daemon starts on its own.
./gradlew --stop
./gradlew assembleDebug3Verify
The build runs, and --status shows a new daemon.
./gradlew --statusConfirmed by docs.gradle.org
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.properties2Fix
Close memory-heavy apps, and set an explicit heap for the daemon in gradle.properties.
# gradle.properties
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g3Verify
Stop the old daemon so the new setting applies, then build again.
./gradlew --stop
./gradlew assembleDebugConfirmed by docs.gradle.org
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 --version2Fix
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 --stop3Verify
Run the build from the terminal and from the IDE; --status should show one daemon.
./gradlew --statusConfirmed by docs.gradle.org
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
The Gradle daemon dies in the middle of a Jenkins or CI build
Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)
The process that runs your build vanished before it reported back.
2 causes, each with a fixMobile apps
Gradle starts a new daemon every build and says others could not be reused
Starting a Gradle Daemon, 1 busy and 6 stopped Daemons could not be reused, use --status for details
This line is a notice, not a failure.
3 causes, each with a fixMobile apps
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile 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 fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fix