Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Starting Gradle daemon" loop creating endless processes

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?

like image 706
flarn2006 Avatar asked Jul 10 '18 16:07

flarn2006


People also ask

How do I stop gradle daemon from running?

If you want to explicitly stop running Daemon processes for any reason, just use the command gradle --stop . This will terminate all Daemon processes that were started with the same version of Gradle used to execute the command.

How long does it take to start a Gradle daemon?

The daemon takes roughly three minutes to start both on my laptop, as well as on CI servers such as GitLab. I tried disabling the daemon, but that just results in the JVM being forked which is also slow (and recent versions of Gradle docs say to use the daemon even for one-time uses in things like containers, I think).

What is starting a Gradle daemon?

The Gradle Daemon keeps the Gradle Framework initialized and running, and caches project data in memory to improve performance. For a Single Build. To enable the Daemon for a single build, you can simply pass the --daemon argument to your gradle command or Gradle Wrapper script.

How do I know if gradle daemon is running?

How can I find out if the gradle daemon is running? Running in terminal gradle --status will give the status of the gradle. You'll see "No Gradle daemons are running" message if there's no gradle daemon running. Otherwise, you'll see status of the daemon.


Video Answer


1 Answers

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.

like image 85
Ace Avatar answered Oct 15 '22 11:10

Ace