提问人:Rasputin221 提问时间:11/4/2023 最后编辑:Rasputin221 更新时间:11/5/2023 访问量:78
Flutter 构建错误:“dart:js_interop”在此平台上不可用
Flutter build error: 'dart:js_interop' is not available on this platform
问:
当我尝试构建我的 flutter 项目时:
flutter build apk --debug
--> 我收到以下错误:
lib/screens/ListPage.dart:1:8: Error: Dart library 'dart:js_interop' is not available on this platform.
import 'dart:js_interop';
^
Context: The unavailable library 'dart:js_interop' is imported through these packages:
package:easy_cost_splitter => dart:js_interop
Detailed import paths for (some of) the these imports:
package:easy_cost_splitter/main.dart => package:easy_cost_splitter/screens/ListPage.dart => dart:js_interop
Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:dart%3Ajs_interop; message=StandardFileSystem only supports file:* and data:* URIs)
#0 StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:34:7)
#1 asFileUri (package:vm/kernel_front_end.dart:721:37)
#2 writeDepfile (package:vm/kernel_front_end.dart:861:21)
<asynchronous suspension>
#3 FrontendCompiler.compile (package:frontend_server/frontend_server.dart:669:9)
<asynchronous suspension>
#4 starter (package:frontend_server/starter.dart:102:12)
<asynchronous suspension>
#5 main (file:///b/s/w/ir/x/w/sdk/pkg/frontend_server/bin/frontend_server_starter.dart:13:14)
<asynchronous suspension>
Target kernel_snapshot failed: Exception
FAILURE: Build failed with an exception.
* Where:
Script '/home/myname/flutter/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy' line: 1297
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/home/myname/flutter/bin/flutter'' finished with non-zero exit value 1
...
奇怪的是:在提到的文件的第 8 行中,甚至没有引用 js_interop,而是这段代码:
class ListPage extends StatefulWidget {
const ListPage({super.key});
@override
State<ListPage> createState() => _ListPageState();
}
我已经在互联网上搜索并尝试了以下方法,但没有成功:
- 在目录中的所有文件中搜索单词“js_interop”,但没有结果
- flutter clean,然后 flutter pub 得到
- 删除新安装的扩展,如 CMake
- 重新启动 VS Code 和电脑
这是颤振医生的结果:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.13.9, on Linux Mint 21.1 5.15.0-88-generic, locale de_DE.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.83.1)
[✓] Connected device (2 available)
[✓] Network resources
• No issues found!
有人可以帮忙吗?
答:
0赞
jraufeisen
11/4/2023
#1
该包 - 就像 - 仅在为 Web 平台构建时可用。
您的代码将无法在 Android 上运行。dart:js_interop
dart:js
在项目的某个位置,您包含一个依赖项,该依赖项本身依赖于 。dart:js_interop
0赞
Rasputin221
11/5/2023
#2
这有点奇怪。当我查看我的 github 存储库时,有一行导入了包js_interop - 但这只是远程代码版本;我的本地代码没有导入包。我在第一行“//Test”中添加了类“ListPage.dart”,现在它正在运行。无论如何,现在它正在构建一个 apk。
上一个:QEMU 中的 Android
评论