"Starting Gradle daemon" loop creating endless processes

I had the same problem on Linux. I traced it down to a firewall misconfiguration. It prevented Android Studio from communicating with Gradle daemon using IP over loopback interface.


TL;DR: Turn off Windows Mobile Hotspot (aka, adHoc Adapter or Wi-Fi Direct Virtual Adapter) before your first build.

For some reason, while the hotspot is on, gradle server cannot accept incoming connections from /127.0.0.1 according to the log file in %userProfile%\.gradle\daemon\<version>\. And so, it keeps spawning new daemons thinking the old ones (sleeping in wait for connections) are dead.

Every time you need a new gradle daemon (eg. open a new project), you have to turn the hotspot off, wait for AS to connect to the daemon (eg. start building, sync gradle files, etc.), then re-enable it.

Notice that if you forget to disable the hotspot and start a build/sync process, your RAM will be filled with waiting gradle daemons. Kill them all before you try again or you will have an "Insufficient Memory" error.

I use this nice command in a shortcut file to kill all deamons with one click: C:\Windows\System32\taskkill.exe /F /IM java.exe /T. Of course this is assuming you have no java processes other than gradle daemons (which is mostly the case when I'm working on AS), and you don't mind working daemons be restarted (which isn't a big deal imo).

This problem started only after upgrading from AS 4.0 to 4.1 and stayed for the next upgrades too.