Flutter - 在 Android Studio 和 Flutter 更新后 Dart 失败

标签 flutter dart compiler-errors

我有一个运行没有问题的项目,因为我更新到 Android Studio 3.5.3Flutter 1.13.1-pre.99 • channel master ,尝试在真实设备上运行时,同一个项目会出现巨大的错误。

我在这里提到 Android Studio 和 Flutter 更新,因为我不确定它们中的哪一个(如果有)导致了问题。

在我看来,这是 flutter_web 的问题。我前段时间安装的……但我仍然不确定如何卸载 flutter_web 本身。

注意:当前项目不是 flutter web 项目

这里是完整的错误......(对不起,大文​​本):

Invalid depfile: /Users/user458395/Desktop/flutterProjects/testProjectX/.dart_tool/flutter_build/0732b8ad26463ce096dc3cab1564707e/kernel_snapshot.d
Invalid depfile: /Users/user458395/Desktop/flutterProjects/testProjectX/.dart_tool/flutter_build/0732b8ad26463ce096dc3cab1564707e/kernel_snapshot.d

Compiler message:
lib/routes/search_results_route.dart:1:8: Error: Not found: 'dart:html'
import 'dart:html';
       ^
../../../Downloads/flutterSdk/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0+2/lib/src/browser_client.dart:6:8: Error: Not found: 'dart:html'
import 'dart:html';
       ^
../../../Downloads/flutterSdk/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0+2/lib/src/browser_client.dart:97:25: Error: Type 'HttpRequest' not found.
  void _openHttpRequest(HttpRequest request, String method, String url,
                        ^^^^^^^^^^^
../../../Downloads/flutterSdk/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0+2/lib/src/browser_client.dart:32:25: Error: 'HttpRequest' isn't a type.
  final _xhrs = new Set<HttpRequest>();
                        ^^^^^^^^^^^
../../../Downloads/flutterSdk/flutter/packages/flutter/lib/src/painting/_network_image_web.dart:64:12: Error: Method not found: 'webOnlyInstantiateImageCodecFromUrl'.
    return ui.webOnlyInstantiateImageCodecFromUrl(resolved) as Future<ui.Codec>; // ignore: undefined_function
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../Downloads/flutterSdk/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0+2/lib/src/browser_client.dart:46:19: Error: Method not found: 'HttpRequest'.
    var xhr = new HttpRequest();
                  ^^^^^^^^^^^
../../../Downloads/flutterSdk/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0+2/lib/src/browser_client.dart:57:45: Error: Method not found: 'Blob'.
      var blob = xhr.response == null ? new Blob([]) : xhr.response;
                                            ^^^^
../../../Downloads/flutterSdk/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0+2/lib/src/browser_client.dart:58:24: Error: Method not found: 'FileReader'.
      var reader = new FileReader();
                       ^^^^^^^^^^
../../../Downloads/flutterSdk/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0+2/lib/src/browser_client.dart:97:25: Error: 'HttpRequest' isn't a type.
  void _openHttpRequest(HttpRequest request, String method, String url,
                        ^^^^^^^^^^^
Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:dart%3Ahtml; message=StandardFileSystem only supports file:* and data:* URIs)
#0      StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:33:7)
#1      asFileUri (package:vm/kernel_front_end.dart:604:37)
#2      writeDepfile (package:vm/kernel_front_end.dart:799:21)
<asynchronous suspension>
#3      FrontendCompiler.compile (package:frontend_server/frontend_server.dart:472:15)
<asynchronous suspension>
#4      _FlutterFrontendCompiler.compile (package:flutter_frontend_server/server.dart:38:22)
#5      starter (package:flutter_frontend_server/server.dart:149:27)
#6      main (file:///b/s/w/ir/cache/builder/src/flutter/flutter_frontend_server/bin/starter.dart:8:30)
#7      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:32)
#8      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)

Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
build failed.

FAILURE: Build failed with an exception.

* Where:
Script '/Users/user458395/Downloads/flutterSdk/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 792

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/user458395/Downloads/flutterSdk/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 36s
Finished with error: Gradle task assembleDebug failed with exit code 1

最佳答案

编辑 :要摆脱此问题,请通过在终端中运行此命令切换回稳定 channel 。

flutter channel stable
运行 flutter upgrade在这之后。

请通过此命令检查详细错误
flutter run --debug
要记住的一点:如果它不是网络项目,则查找并删除 dart:html .

dart:html library is for web apps only (it wraps the DOM APIs) and it is not supposed run in Flutter. Please check this git issue

关于Flutter - 在 Android Studio 和 Flutter 更新后 Dart 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59309719/

相关文章:

flutter - 根据类型名称动态创建实例

flutter - 如果 widget 多次调用 InheritedWidget.of() 是否有任何性能问题?

c - 当您意外运行无限循环时会发生什么样的错误

c++ - 具有重载运算符的自定义类在用作映射键时会导致 C2678

flutter - 使用 Cubit Bloc 更新另一个小部件

flutter - 多个设备(android、ios 和 web)使用相同的 google clientId 和 clientSecret

dart - 软件包code_transformers没有匹配的版本

flutter - 将小部件分解并换行到一行中的下一行,但从父小部件的最左边开始

java - 如何使用 EventChannel 从 native 服务广播接收器接收数据流?

c# - 为什么在构建期间出现此错误?提到一些有关无法调试的信息