Flutter - FAILURE:构建失败并出现异常。 - 无法启动守护进程。 - 安卓工作室 - VSCode

Posted

技术标签:

【中文标题】Flutter - FAILURE:构建失败并出现异常。 - 无法启动守护进程。 - 安卓工作室 - VSCode【英文标题】:Flutter - FAILURE: Build failed with an exception. - Unable to start the daemon process. - Android Studio - VSCode 【发布时间】:2021-06-23 03:29:09 【问题描述】:

每当我尝试使用 flutter run -v 运行 Flutter 应用程序时,都会出现以下错误。如果我不使用终端,只需单击运行,正在运行的 gradle 任务会继续运行,并且没有任何反应。

我试过了:

    已更改 gradle.properties org.gradle.jvmargs=-Xmx1536m => org.gradle.jvmargs:-Xmx1024m 已删除 .gradle 文件 重置我的笔记本电脑

我能做什么?

颤动运行-v

颤振医生

*flutter build apk -v

[  +95 ms] executing: [C:\Flutter\flutter/] git -c log.showSignature=false log -n 1
--pretty=format:%H
[  +73 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[        ] 4d7946a68d26794349189cf21b3f68cc6fe61dcb
[   +1 ms] executing: [C:\Flutter\flutter/] git tag --points-at
4d7946a68d26794349189cf21b3f68cc6fe61dcb
[  +93 ms] Exit code 0 from: git tag --points-at 4d7946a68d26794349189cf21b3f68cc6fe61dcb
[        ] 2.0.3
[  +45 ms] executing: [C:\Flutter\flutter/] git rev-parse --abbrev-ref --symbolic @u
[  +32 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @u
[        ] origin/stable
[        ] executing: [C:\Flutter\flutter/] git ls-remote --get-url origin
[  +30 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[  +82 ms] executing: [C:\Flutter\flutter/] git rev-parse --abbrev-ref HEAD
[  +27 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] stable
[  +85 ms] Artifact Instance of 'androidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'iosEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +2 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +59 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[   +4 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'PubDependencies' is not required, skipping update.
[  +48 ms] Skipping pub get: version match.
[ +133 ms] Generating
C:\Users\Salma\Desktop\Grad\flutter_app\android\app\src\main\java\io\flutter\plugins\GeneratedPlugin
Registrant.java
[ +396 ms] Building without sound null safety
[   +1 ms] For more information see https://dart.dev/null-safety/unsound-null-safety
[  +25 ms] Running Gradle task 'assembleRelease'...
[   +8 ms] Using gradle from C:\Users\Salma\Desktop\Grad\flutter_app\android\gradlew.bat.
[   +5 ms] C:\Users\Salma\Desktop\Grad\flutter_app\android\gradlew.bat mode: 33279 rwxrwxrwx.
[  +10 ms] executing: C:\Program Files\Android\Android Studio\jre\bin\java -version
[ +187 ms] Exit code 0 from: C:\Program Files\Android\Android Studio\jre\bin\java -version
[   +2 ms] openjdk version "1.8.0_242-release"
           OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
           OpenJDK 64-Bit Server VM (build 25.242-b01, mixed mode)
[   +3 ms] executing: [C:\Users\Salma\Desktop\Grad\flutter_app\android/]
C:\Users\Salma\Desktop\Grad\flutter_app\android\gradlew.bat -Pverbose=true
-Ptarget-platform=android-arm,android-arm64,android-x64 -Ptarget=lib\main.dart
-Ptrack-widget-creation=true -Ptree-shake-icons=true assembleRelease
[+2795 ms] Starting a Gradle Daemon, 100 busy Daemons could not be reused, use --status for details
[+2481 ms] Starting a Gradle Daemon, 101 busy Daemons could not be reused, use --status for details
[+2502 ms] Starting a Gradle Daemon, 102 busy Daemons could not be reused, use --status for details
[  +23 ms] FAILURE: Build failed with an exception.
[   +4 ms] * What went wrong:
[   +2 ms] Unable to start the daemon process.
[   +1 ms] This problem might be caused by incorrect configuration of the daemon.
[   +1 ms] For example, an unrecognized jvm option is used.
[   +1 ms] Please refer to the User Manual chapter on the daemon at
https://docs.gradle.org/6.7/userguide/gradle_daemon.html
[   +1 ms] Process command line: C:\Program Files\Android\Android Studio\jre\bin\java.exe -Xmx1024m
-Dfile.encoding=windows-1252 -Duser.country=US -Duser.language=en -Duser.variant -cp
C:\Users\Salma\.gradle\wrapper\dists\gradle-6.7-all\cuy9mc7upwgwgeb72wkcrupxe\gradle-6.7\lib\gradle-
launcher-6.7.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.7
[   +1 ms] Please read the following process output to find out more:
[   +1 ms] -----------------------
[        ] Error occurred during initialization of VM
[        ] Could not reserve enough space for object heap
[        ] * Try:
[        ] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to
get more log output. Run with --scan to get full insights.
[   +1 ms] * Get more help at https://help.gradle.org
[  +30 ms] Running Gradle task 'assembleRelease'... (completed in 8.1s)
[   +8 ms] "flutter apk" took 8,820ms.
[   +8 ms] Gradle task assembleRelease failed with exit code 1
[   +3 ms] 
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      buildGradleApp (package:flutter_tools/src/android/gradle.dart:411:7)
           <asynchronous suspension>
           #2      _AndroidBuilderImpl.buildApk
(package:flutter_tools/src/android/android_builder.dart:101:7)
           <asynchronous suspension>
           #3      BuildApkCommand.runCommand
(package:flutter_tools/src/commands/build_apk.dart:103:5)
           <asynchronous suspension>
           #4      FlutterCommand.verifyThenRunCommand
           (package:flutter_tools/src/runner/flutter_command.dart:1157:12)
           <asynchronous suspension>
           #5      FlutterCommand.run.<anonymous closure>
           (package:flutter_tools/src/runner/flutter_command.dart:1009:27)
           <asynchronous suspension>
           #6      AppContext.run.<anonymous closure>
(package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #7      AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
           <asynchronous suspension>
           #8      CommandRunner.runCommand (package:args/command_runner.dart:197:13)
           <asynchronous suspension>
           #9      FlutterCommandRunner.runCommand.<anonymous closure>
           (package:flutter_tools/src/runner/flutter_command_runner.dart:278:9)
           <asynchronous suspension>
           #10     AppContext.run.<anonymous closure>
(package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #11     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
           <asynchronous suspension>
           #12     FlutterCommandRunner.runCommand
           (package:flutter_tools/src/runner/flutter_command_runner.dart:234:5)
           <asynchronous suspension>
           #13     run.<anonymous closure>.<anonymous closure>
(package:flutter_tools/runner.dart:64:9)
           <asynchronous suspension>
           #14     run.<anonymous closure> (package:flutter_tools/runner.dart:62:12)
           <asynchronous suspension>
           #15     AppContext.run.<anonymous closure>
(package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #16     AppContext.run (package:flutter_tools/src/base/context.dart:149:12)
           <asynchronous suspension>
           #17     runInContext (package:flutter_tools/src/context_runner.dart:73:10)
           <asynchronous suspension>
           #18     main (package:flutter_tools/executable.dart:90:3)
           <asynchronous suspension>          
[ +117 ms] ensureAnalyticsSent: 113ms
[   +4 ms] Running shutdown hooks
[   +1 ms] Shutdown hooks complete
[   +1 ms] exiting with code 1

【问题讨论】:

您的计算机内存不足。我建议切换到 vscode 并将你的内存升级到至少 8gb @Uni,我的内存 8gb(7.71gb 可用),对于 vscode,它会发出警报,此窗口不再响应颤动运行 这很奇怪。你能发布flutter run --verbose的输出吗? 【参考方案1】:

问题是 OpenJDK 平台二进制文件会打开许多​​实例,这会占用我的内存, 我从这个question 和this answer 中发现了这个问题,说要关闭热点并且确实有效。 在某些情况下,重新启动您的笔记本电脑也可能有效,但并非全部。

我不知道 Hotspot 是怎么出问题的,或者它以什么方式连接到 OpenJDK,如果有人有解释,请发表评论。

【讨论】:

【参考方案2】:

请始终以文本而不是图像的形式发布您的错误日志。

1- 运行 flutter clean 然后再次构建。

2- 你是在模拟器还是物理设备上运行它?

3- 如果在模拟器上,增加该设备的虚拟内存。更好的是,删除模拟器并创建一个新的。

4- 如果还是不行,运行flutter upgrade

5- 您可以将文件构建为 APK 吗?换句话说,不在设备上运行?

6- 请发布flutter build apk -v的输出。

【讨论】:

我在物理设备上运行它 这可能意味着您的设备内存不足。请发布flutter build apk -v 的输出,我们可以查看您的应用程序是否构建,排除这是您的计算机问题或配置与模拟器\手机问题。 我添加了flutter build apk -v输出 @salma.m 这显然是计算机问题,有些东西正在占用您的内存。尝试重新启动计算机,关闭所有内容并打开代码,然后尝试构建它。您使用的是什么操作系统? 我使用的是 Windows 10。

以上是关于Flutter - FAILURE:构建失败并出现异常。 - 无法启动守护进程。 - 安卓工作室 - VSCode的主要内容,如果未能解决你的问题,请参考以下文章

Flutter - FAILURE:构建失败并出现异常。 - 无法启动守护进程。 - 安卓工作室 - VSCode

FAILURE:构建失败并出现异常。 * 其中:构建文件 'D:\AProjects\flutter_app\android\app\build.gradle' 行:24

FAILURE:构建失败,出现异常 flutter error 。帮我

Flutter:FAILURE:构建失败,出现异常无法创建任务':app:compileFlutterBuildDebug'。必须提供 Flutter 源码目录

错误:找不到类型“表元数据”| FAILURE:构建失败并出现异常

Flutter:构建失败并出现异常