在 VS Code 上启动 flutter 应用程序时出现错误
我在网上尝试了很多解决方案,但都没有成功,我也尝试重新安装Windows,但也没有成功
守护进程日志
[10:31:08 PM] [General] [Info] C:\src\flutter\bin\cache\dart-sdk\bin
[10:31:08 PM] [General] [Info] Candidate paths to be post-filtered:
[10:31:08 PM] [General] [Info] C:\src\flutter\bin\cache\dart-sdk
[10:31:08 PM] [General] [Info] C:\src\flutter\bin\cache\dart-sdk
[10:31:08 PM] [General] [Info] Found at C:\src\flutter\bin\cache\dart-sdk
[10:31:08 PM] [General] [Info] Returning SDK path C:\src\flutter\bin\cache\dart-sdk for dart.exe
[10:31:08 PM] [General] [Info] Experiment random number is 69 for experiement 'lsp-default'. Experiment is enabled for <= 10
[10:31:08 PM] [General] [Info] !! PLEASE REVIEW THIS LOG FOR SENSITIVE INFORMATION BEFORE SHARING !!
Dart Code extension: 3.21.1
Flutter extension: 3.21.0 (not activated)
App: Visual Studio Code
Version: 1.55.2
Platform: win
Workspace type: Flutter
Analyzer type: DAS
Multi-root?: false
Dart SDK:
Loc: C:\src\flutter\bin\cache\dart-sdk
Ver: 2.12.3
Flutter SDK:
Loc: C:\src\flutter
Ver: 2.0.6
HTTP_PROXY: undefined
NO_PROXY: undefined
[10:31:08 PM] [General] [Info] Spawning C:\src\flutter\bin\cache\dart-sdk\bin\pub.bat with args ["global","list"]
[10:31:08 PM] [CommandProcesses] [Info] (PROC undefined) Logging data for process...
[10:31:08 PM] [Analyzer] [Info] Spawning C:\src\flutter\bin\cache\dart-sdk\bin\dart.exe with args ["C:\\src\\flutter\\bin\\cache\\dart-sdk\\bin\\snapshots\\analysis_server.dart.snapshot","--client-id=VS-Code","--client-version=3.21.1"]
[10:31:08 PM] [Analyzer] [Info] .. with {"toolEnv":{"FLUTTER_HOST":"VSCode","PUB_ENVIRONMENT":"vscode.dart-code"}}
[10:31:08 PM] [Analyzer] [Info] PID: 5292
[10:31:08 PM] [Analyzer] [Info] ==> {"id":"1","method":"server.setSubscriptions","params":{"subscriptions":["STATUS"]},"clientRequestTime":1619888468969}
[10:31:08 PM] [Analyzer] [Info] ==> {"id":"2","method":"analysis.setPriorityFiles","params":{"files":["D:\\GitHub\\fitify\\lib\\main.dart"]},"clientRequestTime":1619888468973}
[10:31:08 PM] [Analyzer] [Info] ==> {"id":"3","method":"analysis.setSubscriptions","params":{"subscriptions":{"FOLDING":["D:\\GitHub\\fitify\\lib\\main.dart"],"OCCURRENCES":["D:\\GitHub\\fitify\\lib\\main.dart"],"OUTLINE":["D:\\GitHub\\fitify\\lib\\main.dart"]}},"clientRequestTime":1619888468976}
[10:31:08 PM] [Analyzer] [Info] ==> {"id":"4","method":"analysis.updateContent","params":{"files":{"D:\\GitHub\\fitify\\lib\\main.dart":{"content":"import 'package:fitify/pages/app_Inro.dart';\r\nimport 'package:fitify/widgets/color.dart';\r\nimport 'package:flutter/material.dart';\r\n\r\nvoid main() {\r\n runApp(MyApp());\r\n}\r\n\r\nclass MyApp extends StatelessWidget {\r\n @override\r\n Widget build(BuildContext context) {\r\n return MaterialApp(\r\n debugShowCheckedModeBanner: false,\r\n theme: ThemeData(\r…
[10:31:08 PM] [FlutterDaemon] [Info] Spawning C:\src\flutter\bin\flutter.bat with args ["daemon"]
[10:31:08 PM] [FlutterDaemon] [Info] .. in C:\src\flutter
[10:31:08 PM] [FlutterDaemon] [Info] .. with {"toolEnv":{"FLUTTER_HOST":"VSCode","PUB_ENVIRONMENT":"vscode.dart-code"}}
[10:31:08 PM] [FlutterDaemon] [Info] PID: 5292
[10:31:08 PM] [FlutterDaemon] [Info] ==> [{"id":"1","method":"emulator.getEmulators"}]
解决方案:Ubuntu 20.04、adb 33.0.1、Android Studio Bumblebee 2021.1.1:
事件日志显示无法到达 ADB 服务器,这很好。当您使用第 3 点和第 4 点中的命令运行时,adb 将在端口 5037 上启动。如果 Studio 连接到手动启动的 adb,它会杀死它。这就是为什么必须在 Studio 设置中设置 5038(而不是 5037)。
下次重新启动后,您只需执行 4. 和 5.
我已通过以下步骤解决了此错误:
转到 {C://Users/{Name}/.gradle} - 删除 .gradle 文件。
然后在其他位置下载并安装相同的flutter和dart SDK版本并设置环境变量。
Example:
Environment variables Before : ("D:\FlutterExtractedFiles\flutter\bin") ("D:\FlutterExtractedFiles\flutter\bin\cache\dart-sdk\bin")
Environment variables After : ("C:\edgedownloads\flutter_windows_v1.12.13+hotfix.8-stable\flutter\bin") ("C:\edgedownloads\flutter_windows_v1.12.13+hotfix.8-stable\flutter\bin\cache\dart-sdk\bin")
我在 vs code 中也有类似的问题。唯一对我有用的解决方案是从 .vscode/settings.json
中删除所有“--no-sound-null-safety”设置
{
"xd.globalEditor": false,
"xd.lastPackage": "/Users/username/Downloads/material-theme 2",
"java.configuration.updateBuildConfiguration": "automatic",
// "dart.flutterTestAdditionalArgs": ["--no-sound-null-safety"],
// "dart.flutterAdditionalArgs": ["--no-sound-null-safety"],
// "dart.vmAdditionalArgs": ["--no-sound-null-safety"],
}
通过从 android studio 重新连接 SDK 路径到项目,我在 pop os 求解器上遇到了同样的问题。