RustDesk 和 Flutter Web 构建错误 | .dart 文件在尝试 Web 构建时导致错误

问题描述 投票:0回答:1

我在使用“flutter build web --release”命令时遇到很多问题。这是为了进行 Web 构建,以便我可以使用 RustDesk Web 客户端服务。我遇到了很多 .dart 文件无法以 JS 格式正确读取的问题。以下是尝试启动 Web 构建时出现的以下错误:

ptech@rustdeskdev:~/FOO/rustdesk/flutter$ flutter build web --release

Warning: In index.html:97: Local variable for "serviceWorkerVersion" is deprecated. Use "{{flutter_service_worker_version}}" template token instead. See
https://docs.flutter.dev/platform-integration/web/initialization for more details.
Target dart2js failed: ProcessException: Process exited abnormally with exit code 1:
../../../.pub-cache/hosted/pub.dev/firebase_core-3.4.0/lib/src/firebase_app.dart:18:25:
Error: Member not found: 'FirebaseAppPlatform.verify'.
    FirebaseAppPlatform.verify(_delegate);
                        ^^^^^^
lib/pages/scan_page.dart:54:58:
Error: Member not found: 'abgr'.
                            .getBytes(format: img.Format.abgr)
                                                         ^^^^
lib/pages/scan_page.dart:48:41:
Error: The argument type 'Uint8List' can't be assigned to the parameter type 'String'.
 - 'Uint8List' is from 'dart:typed_data'.
                        File(file.path).readAsBytesSync(), file.path)!;
                                        ^
lib/pages/scan_page.dart:48:65:
Error: The argument type 'String' can't be assigned to the parameter type 'Uint8List'.
 - 'Uint8List' is from 'dart:typed_data'.
                        File(file.path).readAsBytesSync(), file.path)!;
                                                                ^
lib/pages/scan_page.dart:54:39:
Error: No named parameter with the name 'format'.
                            .getBytes(format: img.Format.abgr)
                                      ^^^^^^
../../../.pub-cache/hosted/pub.dev/dash_chat-1.1.16/lib/src/message_listview.dart:247:72:
Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't.
                                                                      .text));
                                                                       ^
../../../.pub-cache/hosted/pub.dev/dash_chat-1.1.16/lib/src/widgets/message_container.dart:107:43:
Error: The getter 'accentColor' isn't defined for the class 'ThemeData'.
 - 'ThemeData' is from 'package:flutter/src/material/theme_data.dart' ('../../../rustdesk/flutter/flutter/packages/flutter/lib/src/material/theme_data.dart').
                      ? Theme.of(context).accentColor
                                          ^^^^^^^^^^^
../../../.pub-cache/hosted/pub.dev/dash_chat-1.1.16/lib/src/widgets/quick_reply.dart:43:60:
Error: The getter 'accentColor' isn't defined for the class 'ThemeData'.
 - 'ThemeData' is from 'package:flutter/src/material/theme_data.dart' ('../../../rustdesk/flutter/flutter/packages/flutter/lib/src/material/theme_data.dart').
                      width: 1.0, color: Theme.of(context).accentColor),
                                                           ^^^^^^^^^^^
../../../.pub-cache/hosted/pub.dev/dash_chat-1.1.16/lib/src/widgets/quick_reply.dart:51:46:
Error: The getter 'accentColor' isn't defined for the class 'ThemeData'.
 - 'ThemeData' is from 'package:flutter/src/material/theme_data.dart' ('../../../rustdesk/flutter/flutter/packages/flutter/lib/src/material/theme_data.dart').
                    color: Theme.of(context).accentColor,
                                             ^^^^^^^^^^^
Error: Compilation failed.
  Command: /home/ptech/rustdesk/flutter/flutter/bin/cache/dart-sdk/bin/dart /home/ptech/rustdesk/flutter/flutter/bin/cache/dart-sdk/bin/snapshots/dart2js.dart.snapshot
  --platform-binaries=/home/ptech/rustdesk/flutter/flutter/bin/cache/flutter_web_sdk/kernel --invoker=flutter_tool -Ddart.vm.product=true -DFLUTTER_WEB_AUTO_DETECT=false -DFLUTTER_WEB_USE_SKIA=true
  -DFLUTTER_WEB_CANVASKIT_URL=https://www.gstatic.com/flutter-canvaskit/9c3f66d822e499ee2109dd08b099554bdf2bc93f/ --native-null-assertions --no-source-maps -o
  /home/ptech/FOO/rustdesk/flutter/.dart_tool/flutter_build/5fe9e7ee08d54441cabe9828f988da50/app.dill --packages=/home/ptech/FOO/rustdesk/flutter/.dart_tool/package_config.json --cfe-only
  /home/ptech/FOO/rustdesk/flutter/.dart_tool/flutter_build/5fe9e7ee08d54441cabe9828f988da50/main.dart
#0      RunResult.throwException (package:flutter_tools/src/base/process.dart:122:5)
#1      _DefaultProcessUtils.run (package:flutter_tools/src/base/process.dart:389:19)
<asynchronous suspension>
#2      Dart2JSTarget.build (package:flutter_tools/src/build_system/targets/web.dart:202:5)
<asynchronous suspension>
#3      _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:891:9)
<asynchronous suspension>
#4      Future.wait.<anonymous closure> (dart:async/future.dart:520:21)
<asynchronous suspension>
#5      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:829:32)
<asynchronous suspension>
#6      Future.wait.<anonymous closure> (dart:async/future.dart:520:21)
<asynchronous suspension>
#7      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:829:32)
<asynchronous suspension>
#8      FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:651:16)
<asynchronous suspension>
#9      WebBuilder.buildWeb (package:flutter_tools/src/web/compile.dart:92:34)
<asynchronous suspension>
#10     BuildWebCommand.runCommand (package:flutter_tools/src/commands/build_web.dart:230:5)
<asynchronous suspension>
#11     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1450:27)
<asynchronous suspension>
#12     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
<asynchronous suspension>
#13     CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#14     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:421:9)
<asynchronous suspension>
#15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
<asynchronous suspension>
#16     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:364:5)
<asynchronous suspension>
#17     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:130:9)
<asynchronous suspension>
#18     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
<asynchronous suspension>
#19     main (package:flutter_tools/executable.dart:94:3)
<asynchronous suspension>

Compiling lib/main.dart for the Web...                             13.5s
Error: Failed to compile application for the Web.

为了添加上下文,我尝试遵循以下步骤来了解如何使此构建正常工作:

git clone https://github.com/JelleBuning/rustdesk.git
cd rustdesk
git switch fix_build
cd flutter/web/js

# Install protoc first, see: https://google.github.io/proto-lens/installing-protoc.html
npm install ts-proto
# Only works with vite <= 2.8, see: https://github.com/vitejs/vite/blob/main/docs/guide/build.md#chunking-strategy
npm install [email protected]

# Required for yarn build
npm install yarn -g
npm install typescript -g
npm install protoc -g

yarn build

cd ..

# About details of YUV converter, check this https://github.com/rustdesk/rustdesk/issues/364#issuecomment-1023562050
wget https://github.com/rustdesk/doc.rustdesk.com/releases/download/console/web_deps.tar.gz
# Decompress to the current directory
tar xzf web_deps.tar.gz

cd ..

flutter build web --release
cd build/web
# You could use any server, just an example
python -m http.server 8000

我目前正处于“flutter build web --release”步骤,在这个步骤中我开始遇到完成此任务的问题。

我有 dart2js,它应该帮助编译 .dart 文件中的 JS 使其处于可读状态,尽管当我编译 .dart 文件时,我得到了每个存在的 .dart 文件的非常长的错误列表在开发服务器上,即使指定它只编译给定目录中的一个文件。示例:
ptech@rustdeskdev:~/FOO/rustdesk/flutter$ dart 编译 js ~/FOO/rustdesk/flutter/lib/pages/scan_page.dart

我只需要一点帮助来理解我在处理这些 .dart 文件时做错了什么以及为什么它们似乎一直失败。

javascript flutter dart debian yarnpkg
1个回答
0
投票

在发布问题后,我在周末解决了这个问题。如果其他人碰巧偶然发现这篇文章,需要做的就是跟踪列出错误的每一个 .dart 文件,并逐行替换所有已弃用的代码。我不熟悉 .dart 文件,所以我最初不确定从哪里开始,尽管经过进一步的研究,我能够发现我的解决方案需要是什么。

此外,Flutter 有一个更新,它清除了我收到的一些 .dart 错误,例如为“.abgr”文件扩展名列出的错误,在应用 Flutter 的最新更新后,该错误在其上消失了拥有。

在 firebase_app.dart 中:第 68 行

int get hashCode => hashValues(name, options); 被改为 int get hashCode => Object.hash(name, options);

在 message_listview.dart 中:第 247 行

.文本)); 被改为 。文本 ?? ''));

在 message_container.dart 中:第 107 行

? Theme.of(context).accentColor 被改为 ? Theme.of(context).colorScheme.secondary

在quick_reply.dart中:第51行

颜色:Theme.of(context).accentColor, 被改为 颜色:Theme.of(context).colorScheme.secondary,

在toggle_switch.dart中:第165行和第175行 165号线 ? Theme.of(context).primaryTextTheme.bodyText1!.color 被改为 ? Theme.of(context).primaryTextTheme.bodyLarge?.color 175号线 ? Theme.of(context).textTheme.bodyText1!.color 被改为 ? Theme.of(context).textTheme.bodyLarge?.color

在 html.dart 中:第 30 行

return Future.value(UnmodifyingUint8ListView(_initBytes!)); 被改为 返回 Future.value(Uint8List.fromList(_initBytes!));

在 bzip2.dart 中:第 5、7、9 行 5号线 不可修改Uint8ListView(Uint8List(0)); 被改为 (Uint8List(0)); 7号线 不可修改Uint32ListView(Uint32List(0)); 被改为 (Uint32List(0)); 9号线 不可修改的Int32ListView(Int32List(0)); 被改为 (Int32List(0));

手动更改这些内容以更新已弃用的代码后,我的 Web 构建能够完成,没有任何进一步的错误。我希望这对那些在网络构建的这方面遇到困难的人有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.