16

Whenever I open or create a project in Android Studio, and it starts to do its background build or whatever, it gets to "Starting Gradle daemon", but gets in a loop and never stops repeating that step. As a result, the build never finishes and it keeps creating Gradle daemon processes until the system runs out of memory and freezes.

This is in Ubuntu. It did work previously, and I don't know what could have changed to make it start happening. Has anyone else run into this problem and been able to fix it?

flarn2006
  • 1,483
  • 13
  • 32

4 Answers4

27

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.

Ace
  • 689
  • 6
  • 21
7

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.

mdmt
  • 86
  • 1
  • 2
  • OK, thanks! This was actually on my computer at work, and I've since gotten a new computer there for unrelated reasons. I haven't tried Android Studio on the new computer yet though, and one of the things I copied over was my firewall configuration, so if that was the problem, perhaps it will still happen, and I'll remember your advice. I'll mark this as the accepted answer because it's been a while. So thanks :) – flarn2006 Jan 26 '19 at 21:22
  • 1
    Had the same problem, 'Starting gradle daemon' has stopped looping after I disconnected from VPN. – Coreggon Feb 18 '21 at 09:35
0

I have same Error on Win 10, I searched a lot but nothing helped me.

  • I off/on window firewall, defender, edit rules ...etc. no result

Solution is (may be)

restore all firewall settings.

old style Control Panel → System & Safety → Windows Defender → Restore Defaults

Note: options/words may not very similar, because it translated.


Update 1:

Other solution

is run Build before connect PC to internet, then after Daemon started connect to network, and builds will work fine.

or you can try disabling Daemon, or let it work offline.

I hope this could help someone.

ZaFaR97
  • 71
  • 1
  • 6
-1

I had the same issue and i have tried almost all options , increased my RAM and added SSD to speed up but same issues remains..

Solution is simple : Restart your computer open android studio , then your project and now when building you app just disconnect your pc from wifi and internet and make sure your hotspot is turned off .. Now, i am at ease its working fine .