23

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?

3
  • You may find your question already answered here. stackoverflow.com/questions/37063217/…
    – Kunj Mehta
    Jul 10, 2018 at 17:11
  • @KunjMehta That didn't fix it; it's still stuck endlessly spawning Gradle daemon processes until the system runs out of memory.
    – Sparkette
    Aug 1, 2018 at 20:05
  • @KunjMehta What do you mean?
    – Sparkette
    Aug 8, 2018 at 15:13

4 Answers 4

48

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.

7
  • 3
    This is only solution that works for those who updated their studio from 4.0 to 4.1 , same scenario for me too it worked after turning off the hotspot. Thank you!
    – Hamza Khan
    Nov 16, 2020 at 9:50
  • 4
    Thank you very much!. This stupid bug waste so much of my time. Just turn of hotspot in windows 10.
    – close_file
    Nov 26, 2020 at 0:19
  • 2
    Same problem with enabled hotspot, thank you for seeing this. But still looking for a solution Dec 26, 2020 at 0:28
  • 2
    Your answer saved me so much time thank you Jan 18, 2021 at 14:23
  • 3
    It is working. Thanks a lot. Very weird bug. May 5, 2021 at 18:44
8

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.

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 :)
    – Sparkette
    Jan 26, 2019 at 21:22
  • 1
    Had the same problem, 'Starting gradle daemon' has stopped looping after I disconnected from VPN.
    – Coreggon
    Feb 18, 2021 at 9: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.

0

for me:
disconnected the real device attached for testing,
which, i use for testing apps as well as for internet connection through tethering.

and hurray.

on more study, found that the loose usb cable was culprit.

Not the answer you're looking for? Browse other questions tagged or ask your own question.