美文网首页
flutter iPhone build error

flutter iPhone build error

作者: tom__zhu | 来源:发表于2025-07-14 21:16 被阅读0次

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

相关文章

网友评论

      本文标题:flutter iPhone build error

      本文链接:https://www.haomeiwen.com/subject/ynfdnjtx.html