我正在使用带有 VS Code 的 Windows 10,尽管我也在 PowerShell 上对其进行了测试,并且都产生了相同的结果:
创建一个新的 flutter 程序后,在编辑任何东西之前,我尝试在我的手机上运行它,作为 Tutorial Says ,但我收到一条错误消息,提示“未找到 pubspec.yaml 文件”。我认为问题一定是默认的新应用程序设置有问题,所以我使用了“flutter_gallery”示例。但是,这有完全相同的问题。我已经重新安装了 flutter ,自行安装了 dart 2,删除了 .pub-cache,但没有任何效果。我试着用谷歌搜索这个问题,但我找不到任何东西。
编辑:我正在从 pubspec.yaml 文件所在的 Flutter 项目的根目录运行命令,但仍然出现错误。完整的错误信息是:
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
Do not run this command from the root of your git clone of Flutter.
这是从项目根目录运行dir
的结果:
Mode LastWriteTime Length Name
---- ------------- ------ ----
da---l 2018-04-11 3:45 PM .idea
da---l 2018-04-11 3:45 PM android
da---l 2018-04-11 3:45 PM ios
da---l 2018-04-11 4:19 PM lib
da---l 2018-04-11 3:45 PM test
-a---l 2018-04-11 3:45 PM 120 .gitignore
-a---l 2018-04-11 3:45 PM 292 .metadata
-a---l 2018-04-11 3:45 PM 5425 .packages
-a---l 2018-04-11 3:45 PM 851 hello_world.iml
-a---l 2018-04-11 3:45 PM 1412 hello_world_android.iml
-a---l 2018-04-11 3:59 PM 8882 pubspec.lock
-a---l 2018-04-11 3:59 PM 358 pubspec.yaml
-a---l 2018-04-11 3:45 PM 160 README.md
更新:我仍然不知道是什么导致了问题,但是当我为 Beta 3 重新安装 Flutter 时,它终于工作了。
最佳答案
看起来您正在从不同的目录(可能是父目录)运行 flutter run 命令。
尝试从项目目录运行 flutter run 命令。
关于dart - 如何在 flutter 中修复 "No pubspec.yaml file found"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49786432/