Flutter macOS/iOS运行时pod install失败问题求助
Flutter macOS/iOS应用pod install失败及ffi架构不兼容问题
问题描述
运行Flutter macOS/iOS应用时遭遇pod install失败,安装CocoaPods 1.15.2过程中,因系统Ruby版本为2.6.10,需手动安装drb 2.0.6和activesupport 6.1.7.8才能完成CocoaPods的安装。但安装完成后启动应用仍报错,错误日志显示ffi_c.bundle存在架构不兼容问题:当前编译为arm64架构,系统需要x86_64h架构。
已尝试的修复步骤
- 执行
flutter clean - 删除macos目录下
Pods/.symlinks等文件 - 执行
flutter pub get - 重新执行
pod install
flutter doctor -v 信息
[✓] Flutter (Channel stable, 3.24.3, on macOS 12.7.6 21H1320 darwin-x64, locale en-GB) • Flutter version 3.24.3 on channel stable at /Users/jan/src/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 2663184aa7 (3 weeks ago), 2024-09-11 16:27:48 -0500 • Engine revision 36335019a8 • Dart version 3.5.3 • DevTools version 2.37.3 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/jan/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160) • All Android licenses accepted. [!] Xcode - develop for iOS and macOS (Xcode 14.2) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14C18 ! Flutter recommends a minimum Xcode version of 15. Download the latest version or update via the Mac App Store. • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.3) • 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.10+0-17.0.10b1087.21-11572160) [✓] IntelliJ IDEA Community Edition (version 2023.2.1) • IntelliJ at /Users/jan/Applications/IntelliJ IDEA Community Edition.app • 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 [✓] VS Code (version 1.94.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.98.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-x64 • macOS 12.7.6 21H1320 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 125.0.6422.61 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category.
解决方案
1. 强制ffi编译为x86_64架构
在终端执行以下命令,指定ffi的编译架构:
gem uninstall ffi arch -x86_64 gem install ffi -- --enable-libffi-alloc
2. 以x86_64模式执行pod install
进入项目的macos目录,用Rosetta模式运行pod install:
cd macos arch -x86_64 pod install
3. 更新Xcode到推荐版本
flutter doctor提示Xcode 14.2低于官方推荐的15版本,更新Xcode可解决部分架构兼容问题,建议通过App Store安装最新版Xcode。
4. 完整清理并重新构建项目
执行以下完整流程,确保彻底清理冗余文件后重新构建:
flutter clean rm -rf macos/Pods macos/Podfile.lock flutter pub get cd macos arch -x86_64 pod install cd .. flutter run
内容的提问来源于stack exchange,提问作者Jan Kreimeyer
相关产品推荐
相关产品推荐

