Flutter在`flutter`命令失败

时间:2015-11-10 02:52:25

标签: dart flutter

我遵循Getting Started with Flutter指南并在运行实际的flutter命令时遇到困难:

flutter init -o my_app
Resolving dependencies...
Error on line 17, column 16 of pubspec.yaml: Invalid version constraint: Could not parse version "^1.4.0". Unknown text at "^1.4.0".
  stack_trace: ^1.4.0
               ^^^^^^
Unhandled exception:
Uncaught Error: FileSystemException: Cannot open file, path = '/Users/craig/Code/flutter/packages/flutter_tools/packages/sky_tools/executable.dart' (OS Error: No such file or directory, errno = 2)
Stack Trace:
#0      _File.open.<anonymous closure> (dart:io/file_impl.dart:349)
#1      _RootZone.runUnary (dart:async/zone.dart:1151)
#2      _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:496)
#3      _Future._propagateToListeners (dart:async/future_impl.dart:579)
#4      _Future._completeWithValue (dart:async/future_impl.dart:339)
#5      _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:401)
#6      _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#7      _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#8      _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:84)
#9      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:131)

#0      _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:883)
#1      _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#2      _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#3      _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:84)
#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:131)
Unhandled exception:
Uncaught Error: FileSystemException: Cannot open file, path = '/Users/craig/Code/flutter/bin/cache/flutter_tools.snapshot' (OS Error: No such file or directory, errno = 2)
Stack Trace:
#0      _File.open.<anonymous closure> (dart:io/file_impl.dart:349)
#1      _RootZone.runUnary (dart:async/zone.dart:1151)
#2      _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:496)
#3      _Future._propagateToListeners (dart:async/future_impl.dart:579)
#4      _Future._completeWithValue (dart:async/future_impl.dart:339)
#5      _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:401)
#6      _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#7      _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#8      _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:84)
#9      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:131)

#0      _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:883)
#1      _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#2      _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#3      _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:84)
#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:131)

4 个答案:

答案 0 :(得分:19)

您的Dart版本似乎已过时< 1.9.2 尝试使用dart --version获取已安装的Dart SDK的版本 当前为1.12.x

更新2018-03-20

在迁移阶段到Dart 2期间,您可能希望从dev频道安装Dart以获得2.0.0-alpha.x版本。 最新的稳定版本是1.24.x

例如

brew install dart --devel

更新2018-06-21

现在也支持:

brew install dart@2

答案 1 :(得分:5)

对于遇到类似错误的其他人,我建议您仔细阅读文档。我没有,因此我浪费了一些时间寻找其他地方的解决方案,即使它始终在我眼前:https://flutter.io/setup-macos/#update-your-path

我正在编写命令,以便您可以在终端窗口中轻松复制和粘贴它们:

touch $HOME/.bash_profile
open $HOME/.bash_profile

第1行创建名为.bash_profile的文本文件。第2行打开它。

然后,下面给出的行必须粘贴在文本文件中:

export PATH=[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin:$PATH

粘贴后不要忘记保存文件。 flutter doctor现在应该适用于每个终端窗口。

答案 2 :(得分:2)

打开您的终端并运行它

export PATH=[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin:$PATH

然后运行 flutter ,它将起作用。

答案 3 :(得分:1)

这是因为您设置的路径是临时的。要添加路径

导出PATH = [PATH_TO_FLUTTER_GIT_DIRECTORY] / flutter / bin:$ PATH

[PATH_TO_FLUTTER_GIT_DIRECTORY]->下载flutter或从git复制的文件夹。

然后做

回显$ PATH

观看此视频即可轻松安装 https://www.youtube.com/watch?v=Em8igImhBKc