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

时间:2019-12-12 17:15:23

标签: flutter dart compiler-errors

我有一个正在运行的项目,没有任何问题,而且由于我将其更新为Android Studio 3.5.3Flutter 1.13.1-pre.99 • channel master,因此当试图在真实设备上运行时,同一项目会产生巨大的错误。

我在这里提到的是Android Studio和Flutter更新,因为我不知道它们中的哪一个(如果有)会引起问题。

在我看来,flutter_web好像是我之前安装的一个问题...但是我仍然不确定如何卸载flutter_web本身。

注意:当前项目不是复杂的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

5 个答案:

答案 0 :(得分:7)

运行:

Flutter clean

然后

Flutter run --debug

为我工作。

答案 1 :(得分:3)

在您的项目中找到dart:html并将其删除。

然后运行flutter clean

在我的情况下,由于某种未知的原因,有时我的IDE(VSCode)创建了导入到我一个文件中的文件,而没有引起我的注意。

答案 2 :(得分:2)

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

flutter channel stable

请通过此命令检查详细错误

flutter run --debug
  

另外,   dart:html库仅适用于Web应用程序(它包装DOM API),并且不应在Flutter中运行。   请检查this git issue

答案 3 :(得分:0)

只需升级颤振即可解决问题:

flutter upgrade

答案 4 :(得分:0)

即使使用稳定分支,仍然存在相同的问题: flutter --version Flutter 1.17.5 • channel stable • https://github.com/flutter/flutter.git Framework • revision 8af6b2f038 (4 weeks ago) • 2020-06-30 12:53:55 -0700 Engine • revision ee76268252 Tools • Dart 2.8.4