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

苹果M1芯片运行Flutter项目报'upb/msg.h' file not found错误如何解决

Flutter iOS运行报错「fatal error: 'upb/msg.h' file not found」修复方案

该错误由旧版本firebase_core、cloud_firestore依赖的upb protobuf库与iOS构建环境不兼容导致,可按以下步骤修复:

  • 清理项目本地缓存与iOS旧依赖
    执行以下命令:
    flutter clean
    rm -rf ios/Pods ios/Podfile.lock
    
  • 配置Podfile强制锁定兼容的upb版本
    打开iOS目录下的Podfile,在末尾的post_install区块添加配置,修改后完整区块如下:
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        flutter_additional_ios_build_settings(target)
        target.build_configurations.each do |config|
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
            '$(inherited)',
            'PB_FIELD_32BIT=1'
          ]
        end
      end
      pod 'upb', '1.23.0'
    end
    
  • (长期稳定方案可选)升级Firebase相关依赖到适配版本
    修改pubspec.yaml依赖配置:
    dependencies:
      flutter:
        sdk: flutter
      firebase_core: ^2.15.0
      cloud_firestore: ^4.8.0
      cupertino_icons: ^1.0.2
    
    修改后执行flutter pub get拉取新版本依赖。
  • 重新安装iOS依赖并运行项目
    进入项目ios目录执行以下命令:
    pod install --repo-update
    
    若使用M系列芯片Mac设备,需执行以下命令替代:
    arch -x86_64 pod install --repo-update
    
    回到项目根目录重新运行应用即可。

提示:若执行完以上步骤仍报错,可删除Xcode派生数据后重新构建,路径为~/Library/Developer/Xcode/DerivedData

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 07:09:03