flutter iPhone build error

vs code 在 iPhone 编译报错

vs code 在 iPhone 编译 flutter 项目

==  vs code 日志显示 ==

Launching lib/main.dart on Tom iPhone 15 Pro in debug mode...
Automatically signing iOS for device deployment using specified development team in Xcode project: R33E8MCGY3
Xcode build done.                                           19.9s
You may be prompted to give access to control Xcode. Flutter uses Xcode to run your app. If access is not allowed, you can change this through your Settings > Privacy & Security > Automation.
Error connecting to the service protocol: failed to connect to http://127.0.0.1:51379/LJmpI_WqDmI=/

== Xcode 日志显示 == 

NSBundle file:///System/Library/PrivateFrameworks/MetalTools.framework/ principal class is nil because all fallbacks have failed
fopen failed for data file: errno = 2 (No such file or directory)
Errors found! Invalidating cache...
fopen failed for data file: errno = 2 (No such file or directory)
Errors found! Invalidating cache...
flutter: The Dart VM service is listening on http://127.0.0.1:49267/LJmpI_WqDmI=/```

解决办法
fvm flutter clean && fvm flutter pub get && fvm flutter run
删除 APP 重新编译

1. iOS

确保你的 Flutter 应用有正确的网络权限
在 Info.plist 中添加

<key>NSLocalNetworkUsageDescription</key>
<string>用于调试目的</string>
<key>NSBonjourServices</key>
<array>
<string>_dartobservatory._tcp</string>
</array>

2. iOS 或是 Android

端口被占用,杀死占用的进程,再重新编译

  1. 定位进程 lsof -i :{port}

安卓也会遇到类似情况,有可能是 ADB 链接不稳。如果是通过 USB 连接,ADB 驱动或服务可能不稳定,导致连接中断。换一根原装数据线可以解决问题

不考虑调试,仅运行的情况可以用下面命令指定 port运行
flutter run --host-vmservice-port=65432

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容