Tip: How to reuse Gradle daemon between Android Studio and terminal

When I run first gradle command from terminal, it starts new daemon instead of reusing already existed one.

Starting a Gradle Daemon, 1 incompatible and 0 stopped Daemons could not be reused, use — status for details

That’s strange, because Android Studio already started one daemon and I want to reuse it.

Why I want to reuse existing daemon

  • New daemon is not “warmed up” and cannot reuse anything from existed daemon
  • It consumes additional memory

Why daemon from Android Studio is not compatible for terminal

There are two main reason to be incompatible — Gradle version and Java version. Gradle version should be the same, but JDK versions are different. By default, Android Studio is using embedded JDK, which most likely has a different version from Java installed on your machine.

How to make daemon compatible

In Android Studio go to Project Structure -> SDK location. Uncheck “Use embedded JDK” and specify for JDK.

Set JDK location in Project Structure

On Mac you can easily find JDK location by executing

echo $(/usr/libexec/java_home)

How to see how many daemons are running

Execute gradle --status

PS. This applies to Gradle wrapper and locally installed Gradle. I recommend to use local Gradle distribution. See my previous Tip to find out why.