VS Code 命令托盘中的 Flutter 找不到 git
Posted
技术标签:
【中文标题】VS Code 命令托盘中的 Flutter 找不到 git【英文标题】:Flutter in VS Code command pallete doesn't find git 【发布时间】:2020-04-23 17:32:12 【问题描述】:我一直在尝试在我的笔记本电脑上设置 Flutter,但没有成功。问题很可能出在 VS Code 中的扩展或某些东西上。我可以从 Powershell 运行颤振命令没问题。但是从 VS Code 命令面板执行的命令报告如下:
[flutter] flutter doctor -v
'where' is not recognized as an internal or external command,
operable program or batch file.
Error: Unable to find git in your PATH.
exit code 1
这很奇怪,我的计算机设置中确实有 git 可以直接从 Powershell 工作 - 它在 PATH 中。此外,命令面板中可用的来自 VS Code 的 GIT 命令也可以正常工作。
我能够检查的每个日志都报告上述消息或仅报告“位置”部分。
请帮忙,如果您需要任何其他信息,我很乐意提供。谢谢你:)
编辑#1: Flutter Doctor 现在会产生崩溃。它以前工作过,但现在它报告错误。这是它生成的日志:
```
Flutter crash report; please file at https://github.com/flutter/flutter/issues.
## command
flutter doctor
## exception
ArgumentError: Invalid argument(s): Cannot find executable for where.
```
#0 _getExecutable (package:process/src/interface/local_process_manager.dart:127:5)
#1 LocalProcessManager.runSync (package:process/src/interface/local_process_manager.dart:94:30)
#2 _WindowsUtils._which (package:flutter_tools/src/base/os.dart:239:49)
#3 OperatingSystemUtils.whichAll (package:flutter_tools/src/base/os.dart:52:43)
#4 androidSdk.locateAndroidSdk.findAndroidHomeDir (package:flutter_tools/src/android/android_sdk.dart:336:38)
#5 AndroidSdk.locateAndroidSdk (package:flutter_tools/src/android/android_sdk.dart:360:53)
#6 AppContext._generateIfNecessary.<anonymous closure> (package:flutter_tools/src/base/context.dart:100:41)
#7 _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:293:23)
#8 AppContext._generateIfNecessary (package:flutter_tools/src/base/context.dart:88:20)
#9 AppContext.get (package:flutter_tools/src/base/context.dart:117:32)
#10 AppContext.get (package:flutter_tools/src/base/context.dart:115:23)
#11 AppContext.get (package:flutter_tools/src/base/context.dart:115:23)
#12 androidSdk (package:flutter_tools/src/android/android_sdk.dart:19:38)
#13 AndroidWorkflow.canListDevices (package:flutter_tools/src/android/android_workflow.dart:45:41)
#14 AndroidDevices.canListAnything (package:flutter_tools/src/android/android_device.dart:62:47)
#15 DeviceManager.canListAnything.<anonymous closure> (package:flutter_tools/src/device.dart:148:80)
#16 Iterable.any (dart:core/iterable.dart:388:15)
#17 DeviceManager.canListAnything (package:flutter_tools/src/device.dart:148:33)
#18 _DefaultDoctorValidatorsProvider.validators (package:flutter_tools/src/doctor.dart:90:25)
#19 Doctor.validators (package:flutter_tools/src/doctor.dart:145:46)
#20 Doctor.startValidatorTasks (package:flutter_tools/src/doctor.dart:151:39)
#21 Doctor.diagnose (package:flutter_tools/src/doctor.dart:252:41)
#22 DoctorCommand.runCommand (package:flutter_tools/src/commands/doctor.dart:59:39)
#23 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:615:18)
#24 _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:73:64)
#25 _rootRunUnary (dart:async/zone.dart:1134:38)
#26 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#27 _FutureListener.handleValue (dart:async/future_impl.dart:139:18)
#28 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:680:45)
#29 Future._propagateToListeners (dart:async/future_impl.dart:709:32)
#30 Future._completeWithValue (dart:async/future_impl.dart:524:5)
#31 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:554:7)
#32 _rootRun (dart:async/zone.dart:1126:13)
#33 _CustomZone.run (dart:async/zone.dart:1023:19)
#34 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
#35 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
#36 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#37 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
#38 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#39 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:175:5)
```
## flutter doctor
```
encountered exception: Invalid argument(s): Cannot find executable for where.
#0 _getExecutable (package:process/src/interface/local_process_manager.dart:127:5)
#1 LocalProcessManager.runSync (package:process/src/interface/local_process_manager.dart:94:30)
#2 _WindowsUtils._which (package:flutter_tools/src/base/os.dart:239:49)
#3 OperatingSystemUtils.whichAll (package:flutter_tools/src/base/os.dart:52:43)
#4 AndroidSdk.locateAndroidSdk.findAndroidHomeDir (package:flutter_tools/src/android/android_sdk.dart:336:38)
#5 AndroidSdk.locateAndroidSdk (package:flutter_tools/src/android/android_sdk.dart:360:53)
#6 AppContext._generateIfNecessary.<anonymous closure> (package:flutter_tools/src/base/context.dart:100:41)
#7 _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:293:23)
#8 AppContext._generateIfNecessary (package:flutter_tools/src/base/context.dart:88:20)
#9 AppContext.get (package:flutter_tools/src/base/context.dart:117:32)
#10 AppContext.get (package:flutter_tools/src/base/context.dart:115:23)
#11 androidSdk (package:flutter_tools/src/android/android_sdk.dart:19:38)
#12 AndroidWorkflow.canListDevices (package:flutter_tools/src/android/android_workflow.dart:45:41)
#13 AndroidDevices.canListAnything (package:flutter_tools/src/android/android_device.dart:62:47)
#14 DeviceManager.canListAnything.<anonymous closure> (package:flutter_tools/src/device.dart:148:80)
#15 Iterable.any (dart:core/iterable.dart:388:15)
#16 DeviceManager.canListAnything (package:flutter_tools/src/device.dart:148:33)
#17 _DefaultDoctorValidatorsProvider.validators (package:flutter_tools/src/doctor.dart:90:25)
#18 Doctor.validators (package:flutter_tools/src/doctor.dart:145:46)
#19 Doctor.startValidatorTasks (package:flutter_tools/src/doctor.dart:151:39)
#20 Doctor.diagnose (package:flutter_tools/src/doctor.dart:252:41)
#21 _doctorText.<anonymous closure> (package:flutter_tools/runner.dart:205:26)
#22 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:146:29)
#23 _rootRun (dart:async/zone.dart:1126:13)
#24 _CustomZone.run (dart:async/zone.dart:1023:19)
#25 _runZoned (dart:async/zone.dart:1518:10)
#26 runZoned (dart:async/zone.dart:1465:12)
#27 AppContext.run (package:flutter_tools/src/base/context.dart:145:18)
#28 _doctorText (package:flutter_tools/runner.dart:204:19)
#29 _createLocalCrashReport (package:flutter_tools/runner.dart:182:32)
#30 _handleToolError (package:flutter_tools/runner.dart:138:31)
<asynchronous suspension>
#31 run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:68:22)
<asynchronous suspension>
#32 _rootRun (dart:async/zone.dart:1126:13)
#33 _CustomZone.run (dart:async/zone.dart:1023:19)
#34 _runZoned (dart:async/zone.dart:1518:10)
#35 runZoned (dart:async/zone.dart:1502:12)
#36 run.<anonymous closure> (package:flutter_tools/runner.dart:61:18)
<asynchronous suspension>
#37 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:146:29)
#38 _rootRun (dart:async/zone.dart:1126:13)
#39 _CustomZone.run (dart:async/zone.dart:1023:19)
#40 _runZoned (dart:async/zone.dart:1518:10)
#41 runZoned (dart:async/zone.dart:1465:12)
#42 AppContext.run (package:flutter_tools/src/base/context.dart:145:18)
#43 runInContext (package:flutter_tools/src/context_runner.dart:64:24)
#44 run (package:flutter_tools/runner.dart:50:10)
#45 main (package:flutter_tools/executable.dart:65:9)
#46 main (file:///C:/b/s/w/ir/k/archive/flutter/packages/flutter_tools/bin/flutter_tools.dart:8:3)
#47 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:32)
#48 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
```
【问题讨论】:
【参考方案1】:我升级到flutter 1.19.0-3时遇到了同样的问题,我解决了。 此问题可能是由“路径变量”引起的,建议您确保您的路径包含以下所有路由。 'system32、Git bin、flutter bin 和 powershell'。如果您使用的是 Windows,这些路由通常如下所示,因此您可以将以下行复制到您的“路径变量”中。
C:\Windows\System32;
C:\Program Files\Git\bin
C:\flutter\bin;
%systemroot%\System32\WindowsPowerShell\v1.0\;
%SystemRoot%\system32;%SystemRoot%;
【讨论】:
是的,这就是我在解决方案中评论的内容。由于某种原因,我错过了第一行(在你的情况下)。有趣的是更新是如何搞砸的。【参考方案2】:在您的计算机上安装 git desktop 并重新启动您的 IDE。
【讨论】:
我已经按照你的要求做了。还是行不通。除了 VSCode Flutter 任务之外,我可以在任何其他终端上使用 git。 你检查环境变量中的git路径了吗? 是的,它就在那里。我也在 VSCode 中明确设置了 git.exe 的路径,但这并没有改变。 PATH 必须指向 Git 中的“bin”目录,对吗? 是的,你是对的。你可以使用 android studio 或 intelj 作为 IDE 我还没试过。我会在今天晚些时候回来报告。【参考方案3】:所以,我的 PATH
变量中缺少 C:\Windows\System32
值。我的 PATH 中有 Powershell,但没有 System32。要让 Flutter 工作,你需要两者。
我对任何有类似错误的人的建议是,检查 PATH 变量的默认值并将它们设置回去 :)
【讨论】:
以上是关于VS Code 命令托盘中的 Flutter 找不到 git的主要内容,如果未能解决你的问题,请参考以下文章
“flutter pub run build_runner watch --delete-conflicting-outputs”的 VS Code 键盘快捷键
如何将 VS Code 中的 Flutter 与 BlueStacks 4 模拟器连接起来?