You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter集成Firebase后iOS编译遇ARM64架构不兼容问题求助

解决Flutter+Firebase项目运行时的ffi架构不兼容错误

我从零创建了一个Flutter项目并添加了Firebase依赖:

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  firebase_core: ^2.10.0

未进行其他操作直接运行项目时,出现如下错误:

LoadError - dlopen(/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle, 0x0009): tried: '/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')),
'/System/Volumes/Preboot/Cryptexes/OS/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle' (no such file), '/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle' (mach-o file, but is an incompatible architecture (have 'x86_64', need
'arm64')) - /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle

修复步骤

  • 重新安装适配arm64架构的ffi gem
    打开终端执行以下命令:

    sudo arch -x86_64 gem uninstall ffi
    arch -arm64 gem install ffi --version 1.15.5
    

    先卸载原有的x86版本,再安装适配arm64的对应版本(错误日志里的ffi版本是1.15.5)。

  • 用Rosetta兼容模式运行终端
    针对M系列芯片Mac,右键终端图标选择「使用Rosetta打开」,在这个终端里执行flutter run,强制以x86架构兼容模式运行项目。

  • 更新Flutter与Firebase依赖
    执行命令升级Flutter到最新稳定版:

    flutter upgrade
    

    把pubspec.yaml中的firebase_core版本更新到最新兼容版,再执行:

    flutter pub get
    
  • 清理项目缓存并重新构建
    执行以下命令清理Flutter和iOS端缓存,重新安装依赖:

    flutter clean
    cd ios && pod deintegrate && pod install && cd ..
    

内容的提问来源于stack exchange,提问作者Bertuz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 00:13:18