【问题标题】:How to fix "Failed to snapshot build script"如何修复“无法快照构建脚本”
【发布时间】:2019-09-12 10:37:54
【问题描述】:

我为 web 和 dart sdk 安装了颤振。添加到路径 bin 文件夹。跑flutter pub global activate webdevflutter pub upgrade,但输入webdev serve后总是报错”:

[SEVERE] Failed to snapshot build script .dart_tool/build/entrypoint/build.dart.
[SEVERE] This is likely caused by a misconfigured builder definition.
[SEVERE] /C:/flutter/.pub-cache/hosted/pub.dartlang.org/protobuf-0.13.16/lib/src/protobuf/builder_info.dart:43:34: Error: Method not found: 'MapFieldInfo.map'.    _addField(MapFieldInfo<K, V>.map(name, tagNumber, index, PbFieldType.M,                                 ^^^/C:/flutter/.pub-cache/hosted/pub.dartlang.org/protobuf-0.13.16/lib/src/protobuf/field_info.dart:45:9: Error: '_mapEntryBuilderInfo' isn't an instance field of this class.        _mapEntryBuilderInfo = null {        ^^^^^^^^^^^^^^^^^^^^/C:/flutter/.pub-cache/hosted/pub.dartlang.org/protobuf-0.13.16/lib/src/protobuf/field_info.dart:61:9: Error: '_mapEntryBuilderInfo' isn't an instance field of this class.        _mapEntryBuilderInfo = null;        ^^^^^^^^^^^^^^^^^^^^/C:/flutter/.pub-cache/hosted/pub.dartlang.org/protobuf-0.13.16/lib/src/protobuf/field_info.dart:68:9: Error: '_mapEntryBuilderInfo' isn't an instance field of this class.        _mapEntryBuilderInfo = null {        ^^^^^^^^^^^^^^^^^^^^/C:/flutter/.pub-cache/hosted/pub.dartlang.org/protobuf-0.13.16/lib/src/protobuf/field_info.dart:82:12: Error: '_mapEntryBuilderInfo' isn't an instance field of this class.      this._mapEntryBuilderInfo])           ^^^^^^^^^^^^^^^^^^^^/C:/flutter/.pub-cache/hosted/pub.dartlang.org/protobuf-0.13.16/lib/src/protobuf/field_info.dart:199:9: Error: Superclass has no constructor named 'FieldInfo._'.      : super._(        ^^^^^/C:/flutter/.pub-cache/hosted/pub.dartlang.org/protobuf-0.13.16/lib/src/protobuf/field_info.dart:195:21: Error: Final field '_mapEntryBuilderInfo' is not initialized.Try to#7      _CommandRunner.runCommand (package:webdev/src/webdev_command_runner.dart:38:24)
<asynchronous suspension>
#8      CommandRunner.run.<anonymous closure> (package:args/command_runner.dart:112:25)
#9      new Future.sync (dart:async/future.dart:224:31)
#10     CommandRunner.run (package:args/command_runner.dart:112:14)
#11     run (package:webdev/src/webdev_command_runner.dart:19:56)
#12     main (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/webdev-2.5.1/bin/webdev.dart:17:22)
<asynchronous suspension>
#13     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:303:32)
#14     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)

扑医生:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.9.1+hotfix.2, on Microsoft Windows [Version 10.0.18362.356], locale ru-RU)
[X] Android toolchain - develop for Android devices
    X Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/setup/#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
      You may also want to add it to your PATH environment variable.

[!] Android Studio (not installed)
[√] VS Code (version 1.38.1)
[!] Connected device
    ! No devices available

! Doctor found issues in 3 categories.

pubspec.yaml:

name: addd
description: An app built using Flutter for web

environment:
  # You must be using Flutter >=1.5.0 or Dart >=2.3.0
  sdk: '>=2.3.0 <3.0.0'

dependencies:
  flutter_web: any
  flutter_web_ui: any

dev_dependencies:
  build_runner: ^1.5.0
  build_web_compilers: ^2.1.0
  pedantic: ^1.7.0

dependency_overrides:
  flutter_web:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages/flutter_web
  flutter_web_ui:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages/flutter_web_ui

如何解决?

UPD。添加了更多细节(颤振医生和 pubspec.yaml)

【问题讨论】:

  • 您能运行flutter doctor 并提供您的 pubspec.yaml 文件吗?
  • 尝试在dependens中使用protobuf-0.13.15
  • @Nuts 已添加,但我认为颤振医生不会有帮助。
  • 你可以运行pub run build_runner clean 或者pub cache repair
  • @Nuts 没有修复

标签: flutter dart


【解决方案1】:

嗨,我今天也遇到了同样的问题。幸运的是,与工作版本相比,我发现它被 protobuf 版本 > 0.13.15 破坏。

短期修复:

pubspec.yaml下的依赖项下强制将protobuf的版本降级为0.13.15:

dependencies:
  protobuf: <=0.13.15

正常运行pub get,然后运行webdev serve

【讨论】:

  • 正确修复 stagehand 创建的 web-angular 应用程序,其中更新 protobuf 不是一个简单的选项。
【解决方案2】:

我也遇到了同样的问题,但经过一些研究,我发现问题在于 protobuf 版本已过时,请尝试使用 pubspec.yaml 中的 0.14.1 的最新版本

  dependencies:
  protobuf: <=0.14.1

您可以查看最新版本from here

【讨论】:

    【解决方案3】:

    我昨天安装了颤振环境,它工作正常。今天我尝试再次启动该项目并得到同样的错误。

    颤抖的医生

     Doctor summary (to see all details, run flutter doctor -v):
     [√] Flutter (Channel stable, v1.9.1+hotfix.2, on Microsoft Windows [Version 
     10.0.18362.356], locale en-US)
     [X] Android toolchain - develop for Android devices
         X Unable to locate Android SDK.
           Install Android Studio from: https://developer.android.com/studio/index.html
           On first launch it will assist you in installing the Android SDK components.
           (or visit https://flutter.dev/setup/#android-setup for detailed instructions).
           If the Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
           You may also want to add it to your PATH environment variable. 
    
     [!] Android Studio (not installed)
     [!] IntelliJ IDEA Community Edition (version 2019.2)
         X Flutter plugin not installed; this adds Flutter specific functionality.
         X Dart plugin not installed; this adds Dart specific functionality.
     [√] VS Code, 64-bit edition (version 1.38.0)
     [!] Connected device
         ! No devices available
    
     ! Doctor found issues in 4 categories.
    

    pubspec.yaml

     name: demo
     description: An app built using Flutter for web
    
     environment:
       # You must be using Flutter >=1.5.0 or Dart >=2.3.0
       sdk: '>=2.3.0 <3.0.0'
    
     dependencies:
       flutter_web: any
       flutter_web_ui: any
    
     dev_dependencies:
       build_runner: ^1.5.0
       build_web_compilers: ^2.1.0
       pedantic: ^1.7.0
    
     dependency_overrides:
       flutter_web:
         git:
           url: https://github.com/flutter/flutter_web
           path: packages/flutter_web
       flutter_web_ui:
         git:
           url: https://github.com/flutter/flutter_web
           path: packages/flutter_web_ui
    

    【讨论】:

      【解决方案4】:

      我也遇到了这个错误。我面临的问题是我使用了一些不支持空安全的包旧版本。所以我升级了软件包并修复了错误。

      在我的例子中,我使用了较低版本的 freezed 包。并升级它解决了我的问题。与Massaget的问题有关,它的protobuf

      【讨论】:

        猜你喜欢
        • 2020-07-26
        • 1970-01-01
        • 2019-05-03
        • 2023-01-14
        • 1970-01-01
        • 2020-10-01
        • 2010-12-13
        • 2021-10-01
        • 2021-12-17
        相关资源
        最近更新 更多