我尝试使用flutter build web(也尝试过flutter build web --no-sound-null-safety)在发布模式下构建 flutter web 应用程序。当我这样做时,我收到以下错误。
D:\\saves\\reset_password>flutter build web\n\nBuilding without sound null safety\nFor more information see https://dart.dev/null-safety/unsound-null-safety\n\nTarget dart2js failed: Exception: Warning: The \'dart2js\' entrypoint script is deprecated, please use \'dart compile js\' instead.\n.dart_tool/flutter_build/1916f9367c0e6ad6c929bd88cf5227e5/web_plugin_registrant.dart:14:38:\nError: Null safety features are disabled for this library.\nvoid registerPlugins([final Registrar? pluginRegistrar]) {\n ^\nError: Compilation failed.\n\n\nCompiling lib\\main.dart for the Web... 44.9s\nException: Failed to compile application for the Web.Run Code Online (Sandbox Code Playgroud)\r\n当我使用 直接在调试模式下运行它时,它工作正常flutter run。\n注意:我最近升级到 flutter 3.0 并使用 Android studio。\n下面是我的flutter doctor(我知道缺少 android 工具。因为我是为 web 构建的,所以我没有高度重视)
D:\\saves\\reset_password>flutter doctor\nDoctor summary (to see all details, run flutter doctor -v):\n[\xe2\x88\x9a] Flutter (Channel master, 3.1.0-0.0.pre.966, on Microsoft Windows [Version 10.0.19044.1706], locale en-IN)\n[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)\n X cmdline-tools component is missing\n Run `path/to/sdkmanager --install "cmdline-tools;latest"`\n See https://developer.android.com/studio/command-line for more details.\n X Android license status unknown.\n Run `flutter doctor --android-licenses` to accept the SDK licenses.\n See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.\n[\xe2\x88\x9a] Chrome - develop for the web\n[\xe2\x88\x9a] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.5)\n[\xe2\x88\x9a] Android Studio (version 4.1)\n[\xe2\x88\x9a] VS Code (version 1.66.2)\n[\xe2\x88\x9a] Connected device (3 available)\n[\xe2\x88\x9a] HTTP Host Availability\n\n! Doctor found issues in 1 category.Run Code Online (Sandbox Code Playgroud)\r\nvas*_*mar -3
我自己修复了这个错误。这就是我所做的:
我发现文件中有一些pubspec.yaml当前未使用的依赖项。我导航到 my.dart_tool\flutter_build\cb8031cdd1bfbcb95122aae4ad9a63d5\web_plugin_registrant.dart并发现这些依赖项正在内部引用registerPlugins()。
我清除了显示的所有未使用的依赖项,registerPlugins()并执行了以下步骤:
1. flutter pub get
2. flutter clean
3.flutter build web
还有维奥拉!错误消失了,我在build\web文件夹中找到了我的文件。
| 归档时间: |
|
| 查看次数: |
15001 次 |
| 最近记录: |