I’m using this plugin https://github.com/mozilla/rust-android-gradle, which requires me to add
tasks.whenTaskAdded { task ->
if ((task.name == 'javaPreCompileDebug' || task.name == 'javaPreCompileRelease')) {
task.dependsOn 'cargoBuild'
}
}
to my flutter project’s build. Gradle and when I do `flutter build ask I get things like
Starting a Gradle Daemon, 18 busy Daemons could not be reused, use --status for details
Starting a Gradle Daemon, 19 busy Daemons could not be reused, use --status for details
...
and then it keeps starting a new one until my RAM floods and the computer crashes. If I comment on that code, it builds.
Is there a way to debug more to see what is happening? Looking at the system monitor, it’s starting lots of java Gradle daemons
This is part of the output of ./gradlew --info --stack trace --debug assembleDebug
2022-04-24T17:14:45.981+0000 [QUIET] [system.out] > Configure project :
2022-04-24T17:14:45.981+0000 [QUIET] [system.out] Starting a Gradle Daemon, 2 busy and 23 stopped Daemons could not be reused, use --status for details
2022-04-24T17:14:51.958+0000 [LIFECYCLE] [org.gradle.cache.internal.DefaultFileLockManager]
2022-04-24T17:14:51.958+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2022-04-24T17:14:51.958+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2022-04-24T17:14:51.958+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2022-04-24T17:14:51.958+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2022-04-24T17:14:51.958+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2022-04-24T17:14:51.958+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2022-04-24T17:14:46.015+0000 [LIFECYCLE] [org.gradle.internal.logging.progress.ProgressLoggerFactory]
2022-04-24T17:14:46.015+0000 [LIFECYCLE] [org.gradle.internal.logging.progress.ProgressLoggerFactory] > Configure project :
2022-04-24T17:14:54.279+0000 [QUIET] [system.out]
2022-04-24T17:14:54.279+0000 [QUIET] [system.out] > Configure project :
2022-04-24T17:14:54.279+0000 [QUIET] [system.out] Starting a Gradle Daemon, 3 busy and 23 stopped Daemons could not be reused, use --status for details
2022-04-24T17:15:01.958+0000 [LIFECYCLE] [org.gradle.cache.internal.DefaultFileLockManager]
2022-04-24T17:15:01.958+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2022-04-24T17:15:01.958+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2022-04-24T17:15:01.958+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2022-04-24T17:15:01.959+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2022-04-24T17:15:01.959+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2022-04-24T17:15:01.959+0000 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2022-04-24T17:14:54.315+0000 [LIFECYCLE] [org.gradle.internal.logging.progress.ProgressLoggerFactory]
2022-04-24T17:14:54.315+0000 [LIFECYCLE] [org.gradle.internal.logging.progress.ProgressLoggerFactory] > Configure project :
2022-04-24T17:15:02.379+0000 [QUIET] [system.out]
2022-04-24T17:15:02.379+0000 [QUIET] [system.out] > Configure project :
2022-04-24T17:15:02.379+0000 [QUIET] [system.out] Starting a Gradle Daemon, 4 busy and 23 stopped Daemons could not be reused, use --status for details
2022-04-24T17:15:10.279+0000 [QUIET] [system.out]
2022-04-24T17:15:10.279+0000 [QUIET] [system.out] > Configure project :
2022-04-24T17:15:10.279+0000 [QUIET] [system.out] Starting a Gradle Daemon, 5 busy and 23 stopped Daemons could not be reused, use --status for details
my build.gradle
:
buildscript {
ext.kotlin_version = '1.6.21'
repositories {
google()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.mozilla.rust-android-gradle:plugin:0.9.2'
}
gradle version:
distributionUrl=https://services.gradle.org/distributions/gradle-7.4.2-all.zip
UPDATE:
./gradlew --status
PID STATUS INFO
671 IDLE 7.4.2
1026 IDLE 7.4.2
1320 IDLE 7.4.2
2128 IDLE 7.4.2
2470 IDLE 7.4.2
2760 IDLE 7.4.2
3035 IDLE 7.4.2
Only Daemons for the current Gradle version are displayed. See https://docs.gradle.org/7.4.2/userguide/gradle_daemon.html#sec:status
UPDATE:
java --version
openjdk 11.0.14.1 2022-02-08
OpenJDK Runtime Environment (build 11.0.14.1+1-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.14.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)
UPDATE:
flutter --version
Flutter 2.10.5 • channel stable •
https://github.com/flutter/flutter.git
Framework • revision 5464c5bac7 (10 days ago) •
2022-04-18 09:55:37 -0700
Engine • revision 57d3bac3dd
Tools • Dart 2.16.2 • DevTools 2.9.2
UPDATE:
./gradlew --status
PID STATUS INFO
7625 IDLE 7.4.2
694 STOPPED (after the daemon registry became unreadable)
977 STOPPED (after the daemon was no longer found in the daemon registry)
6270 STOPPED (other compatible daemons were started after being idle for 0 minutes and not recently used)
5976 STOPPED (other compatible daemons were started after being idle for 0 minutes and not recently used)
5689 STOPPED (other compatible daemons were started after being idle for 0 minutes and not recently used)
6548 STOPPED (other compatible daemons were started after being idle for 0 minutes and not recently used)
Only Daemons for the current Gradle version are displayed. See https://docs.gradle.org/7.4.2/userguide/gradle_daemon.html#sec:status
2
Answers
The problem of creating Gradle daemons in an endless loop seems to be a connectivity issue, i.e. daemons cannot connect or only have a slow connection and are considered to be dead – so a new daemon is created running into the same problem and so on, until system resources are drained.
Did some research and found this on stackoverflow and maybe even more interesting this as its related to flutter. Workaround described there is to turn off sharing the WiFi connection / using the system as hotspot.
Assuming it’s not a local firewall issue.
File
$GRADLE_USER_HOME/gradle.properties
defines the behavior.One can prevent it from restarting the daemon (the cause may be the plugin and not the daemon):
Or one can disable the daemon altogether:
Better first run with switch
--no-daemon
, as the manual suggests: