Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle demon starting hundred of VMs

Tags:

android

gradle

Android Studio version 4.1.1

Gradle version 6.5

Android Gradle Plugin Version 4.1.0

Start building my android app and I get:

Starting Gradle Daemon...
Gradle Daemon started in 2 s 29 ms
Starting Gradle Daemon...
Gradle Daemon started in 1 s 965 ms
Starting Gradle Daemon...
Gradle Daemon started in 1 s 996 ms
Starting Gradle Daemon...
Gradle Daemon started in 1 s 992 ms
Starting Gradle Daemon...
Gradle Daemon started in 1 s 995 ms

And everyone of those started a separate virtual machine at about 30mb each and it goes like that until my 16Gb of memory is exhausted. First time it happened I had to cut the power off...

And the VMs and their memory consumption survive shutting down Android Studio. I have to kill the processes by hand. Anybody experienced something similar? How do I fix it? I can't build my project anymore. Trying to disable the gradle daemon by using either the environment or the config file didn't work. I am stuck...

like image 964
Gogu CelMare Avatar asked Nov 15 '20 22:11

Gogu CelMare


2 Answers

Thank you @Tormond. Your answer may help somebody else as the issue has to do with the network configuration of the computer. I tried it and it didn't help in may case, but checking the log files of the gradle daemon I spotted issues with the network. Didn't really understand what it was all about but I just disabled all but my physical ethernet connection. Then by excluding one by one I found out that the issue is with the "Mobile Hotspot" provided by my computer. So it is NOT the existence of the wireless but the enabling of the Mobile Hotspot. Now, when I want to use gradle I have to disable the Mobile Hotspot - frustrating!

Also very unsettling that after gradle daemon starts all the VM instances that failed are still there using up memory, and the only way to get rid of them is to go and kill them one by one.

like image 52
Gogu CelMare Avatar answered Oct 03 '22 21:10

Gogu CelMare


Running this solved everything for me (both in AS and CLI):

export _JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"

Then try e.g. ./gradlew assembleDebug after that, or start another build in AS. Let me know if it helps your case too!

This was what pointed me in the right direction: https://stackoverflow.com/a/28655193/3328701

Update: What actually caused this in the firstplace was that I was sharing wifi through ethernet to another computer, if I turn off wifi sharing I no longer need the workaround (preferIPv4Stack=true).

like image 22
Tormod Avatar answered Oct 03 '22 21:10

Tormod