iOS端运行Flutter项目报错:debug_unpack_ios失败,Flutter.framework缺失
问题详情
删除Mac上部分文件释放存储空间后,所有Flutter项目(包括新建空白项目)编译iOS版本时均失败,重装Xcode后问题依旧。
错误日志
Launching lib/main.dart on iPhone 14 in debug mode...
main.dart:1
Xcode build done. 2,8s
Failed to build iOS app
Error (Xcode): Target debug_unpack_ios failed: Exception: Binary /Users/lucasbarreto/developer/test_compile/build/ios/Debug-iphonesimulator/Flutter.framework/Flutter does not exist, cannot thin
Could not build the application for the simulator.
Error launching application on iPhone 14.
Exited
Flutter Doctor检测结果
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.2.1 22D68 darwin-arm64, locale pt-BR) • Flutter version 3.10.6 on channel stable at /Users/lucasbarreto/fvm/versions/3.10.6 • Upstream repository https://github.com/flutter/flutter.git • Framework revision f468f3366c (4 weeks ago), 2023-07-12 15:19:05 -0700 • Engine revision cdbeda788a • Dart version 3.0.6 • DevTools version 2.23.1 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2) • Android SDK at /Users/lucasbarreto/Library/Android/sdk • Platform android-33, build-tools 33.0.2 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 14.3.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14E300c • CocoaPods version 1.12.1 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2022.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) [✓] VS Code (version 1.81.0) • VS Code at /Users/lucasbarreto/Visual Studio Code.app/Contents • Flutter extension version 3.70.0 [✓] VS Code (version 1.79.0-insider) • VS Code at /Users/lucasbarreto/Visual Studio Code - Insiders.app/Contents • Flutter extension version 3.71.20230801 [✓] Connected device (3 available) • iPhone 14 (mobile) • 53A0CEA2-8655-43A6-9523-78D5C99569AD • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 13.2.1 22D68 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 115.0.5790.170 [✓] Network resources • All expected network resources are available.
解决步骤
清理项目缓存与依赖
执行以下命令重置项目状态:flutter clean flutter pub get完成后尝试重新编译项目。
重新安装Flutter引擎(针对FVM用户)
由于你使用FVM管理版本,大概率是Flutter引擎文件被误删,执行:fvm remove 3.10.6 fvm install 3.10.6或者直接清除缓存目录强制重新下载:
rm -rf ~/fvm/versions/3.10.6/bin/cache flutter doctor校验Xcode命令行工具配置
确认Xcode命令行工具路径正确:xcode-select --print-path若输出不是
/Applications/Xcode.app/Contents/Developer,执行:sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer重启终端后再编译。
检查iOS项目框架路径配置
打开项目的ios/Runner.xcworkspace,进入Build Settings:- 找到
Framework Search Paths - 确保包含
$(inherited)和$(FLUTTER_FRAMEWORK_DIR)两个路径
保存配置后重新编译。
- 找到
手动验证Flutter.framework完整性
检查FVM版本目录下的引擎文件:ls -la ~/fvm/versions/3.10.6/bin/cache/artifacts/engine/ios/若缺少
Flutter.framework,执行flutter doctor会自动触发下载;若仍未下载,删除整个cache目录后再次运行flutter doctor。
内容的提问来源于stack exchange,提问作者Lucas Barreto Luz

