【问题标题】:How to run Build runner on Windows 10 from Android Studio如何从 Android Studio 在 Windows 10 上运行 Build runner
【发布时间】:2020-07-09 22:19:22
【问题描述】:

我正在关注 Google 的 Flutter Googlemaps 代码实验室,

https://codelabs.developers.google.com/codelabs/google-maps-in-flutter/#5

G 实验室说

添加此代码后,您的 IDE(如果您正在使用)应该 显示一些红色曲线,因为它引用了一个不存在的兄弟 文件,locations.g.dart。这个生成的文件在无类型之间转换 JSON 结构和命名对象。通过运行创建它 build_runner:

Build runner 应该输出这个:

$ flutter packages pub run build_runner build
[INFO] Generating build script...
[INFO] Generating build script completed, took 291ms

[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 65ms

[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 595ms

[INFO] Running build...
[INFO] 1.2s elapsed, 0/1 actions completed.
[INFO] Running build completed, took 1.2s

[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 27ms

[INFO] Succeeded after 1.2s with 1 outputs (1 actions)

$
  • 我已将 'build_runner: ^1.2.7' dev_dependency 添加到我的 .yaml 文件中,并进行了一些谷歌搜索 周围,​​在 Android Studio 终端中尝试了各种命令,没有一个 得到认可。
  • 我尝试将终端目录从 我的应用程序目录到 C:/flutter 目录,但命令仍然 未被识别。

我不知道该怎么做。在他们从控制台打印出来的光标克拉是 $,它不会出现在 Windows 10 上的 Android Studio 控制台中,所以.... 混乱。

这是请求的 .yaml 文件

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  google_maps_flutter: ^0.5.11
  http: ^0.12.0+1
  json_serializable: ^2.0.2


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.3

dev_dependencies:
  pedantic: ^1.4.0
  build_runner: ^1.2.7
  flutter_test:
    sdk: flutter

【问题讨论】:

  • 你的 pubspec.yaml 是什么样的?
  • @i6x86 已更新。根据实验室的教程,虽然“你的 IDE(如果你正在使用的话)应该显示一些红色曲线,因为它引用了一个不存在的兄弟文件,locations.g.dart。这个生成的文件在无类型的 JSON 结构和命名对象之间转换。创建它通过运行 build_runner:“如何从 Windows 10 或 Android Studio 运行 build_runner?
  • 我在Mac上但是我想Windows也是一样的,你可以在AS的终端运行这个命令:flutter pub run build_runner build
  • 是的,我尝试从 app 目录和 flutter 目录执行此操作,它显示“'flutter' 未被识别为内部或外部命令、可运行程序或批处理文件。”。如果我进入 C:\flutter\bin 并尝试它,它会显示“C:\flutter\bin>flutter pub run build_runner build Error: No pubspec.yaml file found”。此命令应从 Flutter 项目的根目录运行。不要从 Flutter 的 git 克隆的根目录运行此命令。'
  • 你的路径中可能没有添加flutter

标签: android google-maps flutter dart build-runner


【解决方案1】:

@i6x86 正确诊断出问题,我没有完全设置 Flutter。我按照这里的说明进行操作:flutter.dev/docs/get-started/install/windows#update-your-path

重启Android Studio,问题解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-07
    • 1970-01-01
    • 2019-07-03
    • 2015-02-15
    • 1970-01-01
    • 2016-04-03
    相关资源
    最近更新 更多