7

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
mmBs
  • 8,421
  • 6
  • 38
  • 46
Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150
  • What does the suggested `./gradlew --status` give? – cyberbrain Apr 28 '22 at 06:58
  • Hello, could you add your java and react version please ? – Jacouille Apr 28 '22 at 11:56
  • And did you use --status for details? – Oleg Ushakov Apr 28 '22 at 16:19
  • @jacouille updated, and it's flutter – Guerlando OCs Apr 28 '22 at 18:28
  • @OlegUshakov yes, see update please – Guerlando OCs Apr 28 '22 at 18:28
  • Did you try to explicitly stop all daemons before you start the build? (not much hope in that as a solution, but you should try it.) Does the environment variable JAVA_HOME correspond to the version of `java --version` (had funny effects with this in my Ubuntu...) Did you try to clear your caches etc. from ~/.gradle ? (take care that you don't remove any important configs there - rename the folder first and test, before you finally delete it.) – cyberbrain Apr 28 '22 at 21:25
  • @cyberbrain there's no nothing on `JAVA_HOME`, I've cleaned all caches, removed the gradle folder entirely, etc. And the error only happens when the `if ((task.name == 'javaPreCompileDebug'` block is on – Guerlando OCs Apr 29 '22 at 01:13
  • Does `./gradlew cargoBuild` alone also show that behaviour? (remove or comment out the added block in your build.gradle block before) – cyberbrain Apr 29 '22 at 06:59
  • @cyberbrain `./gradlew cargoBuild` without the block works – Guerlando OCs Apr 29 '22 at 11:30
  • As I'm no expert in the fields (neither Rust nor flutter), I would stick with that solution that's also mentioned in the [Usage](https://github.com/mozilla/rust-android-gradle#usage) section of the plugins page you linked - to use the `./gradlew cargoBuild` as last build-step instead of the integration as dependency into some other gradle build task. – cyberbrain May 01 '22 at 18:33
  • I have a feeling this might be a hardware issue. How much RAM does your system have? Is your boot drive almost full? – Abishek Stephen May 03 '22 at 16:52

2 Answers2

3

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):

org.gradle.daemon.performance.enable-monitoring=false

Or one can disable the daemon altogether:

org.gradle.daemon=false

Better first run with switch --no-daemon, as the manual suggests:

If it is suspected that the Daemon process has become unstable, it can simply be killed. Recall that the --no-daemon switch can be specified for a build to prevent use of the Daemon. This can be useful to diagnose whether or not the Daemon is actually the culprit of a problem.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
1

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.

jausen brett
  • 1,111
  • 7
  • 10