Flutter开发中遇到的FileSystemException错误分析与解决
报错内容
Invalid depfile: D:\javadeveloping\Android\workspace\Scanner\.dart_tool\flutter_build\11045792f53d08828ca2719f7c5a9d87\kernel_snapshot.d
Invalid depfile: D:\javadeveloping\Android\workspace\Scanner\.dart_tool\flutter_build\11045792f53d08828ca2719f7c5a9d87\kernel_snapshot.d
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:34:7)
#1 asFileUri (package:vm/kernel_front_end.dart:732:37)
#2 writeDepfile (package:vm/kernel_front_end.dart:870:21)
<asynchronous suspension>
#3 FrontendCompiler.compile (package:frontend_server/frontend_server.dart:676:9)
<asynchronous suspension>
#4 starter (package:frontend_server/starter.dart:102:12)
<asynchronous suspension>
#5 main (file:///C:/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 'D:\javadeveloping\flutter_3.16.7\flutter\packages\flutter_tools\gradle\src\main\groovy\flutter.groovy' line: 1350
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\javadeveloping\flutter_3.16.7\flutter\bin\flutter.bat'' 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 5s
Exception: Gradle task assembleDebug failed with exit code 1
分析原因
FileSystemException(uri=org-dartlang-untranslatable-uri:dart%3Ahtml; message
FileSystemException 是 Dart中表示文件系统操作出错时抛出的异常。错误信息中,uri=org-dartlang-untranslatable-uri:dart%3Ahtml 表示尝试访问的 URI 是 dart:html,这是 Dart的内置库,用于 Web应用程序。
由于 dart:html 不能在没有 Web 浏览器的环境中使用,比如命令行或者服务器环境,所以在这样的环境中尝试访问 dart:html会抛出这个异常。这通常是因为在代码中不小心引入了web相关的dart:html库。
解决办法
- 仔细检查代码中是否有引入dart:html的语句,删除即可
- 如果确实需要web相关功能,可以考虑使用条件导入或平台检测
- 对于iOS开发者,在解决这类编译问题后,可以使用AppUploader这样的iOS开发助手工具来简化后续的测试和发布流程。AppUploader提供了证书管理、打包上传等功能,能帮助开发者更高效地完成应用发布工作
建议在开发过程中保持代码的整洁性,避免引入不必要的库,这样可以减少类似的编译错误发生。同时,合理使用开发工具可以显著提升工作效率。