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

使用EAS构建依赖FCM的Expo iOS项目时遇构建错误求助

解决EAS Build构建Expo iOS项目(Firebase推送相关)失败的思路

一、Expo环境下修改Podfile的两种可行方式

1. 使用Expo Config Plugin(推荐,无需手动管理原生文件)

创建自定义config插件来注入Podfile配置,在项目根目录新建withFirebasePodfix.js:

module.exports = function withFirebasePodfix(config) {
  config.plugins.push({
    func: (config) => {
      const { modResults } = config.modRequest;
      // 在Podfile末尾添加Firebase相关配置
      modResults.contents += `
        pod 'Firebase/Messaging', :modular_headers => true
        pod 'Firebase/Core', :modular_headers => true
      `;
      return config;
    },
  });
  return config;
};

在app.json或app.config.js中引入插件:

{
  "expo": {
    "plugins": ["./withFirebasePodfix.js"]
  }
}

2. 预构建(Prebuild)后手动修改Podfile

执行命令生成iOS原生目录:

npx expo prebuild --platform ios

直接编辑ios/Podfile,添加所需配置:

# 在Podfile末尾追加
pod 'Firebase/Messaging', :modular_headers => true
pod 'Firebase/Core', :modular_headers => true

修改后执行cd ios && pod install,再重新触发EAS Build。注意预构建后需自行维护原生文件,后续Expo版本更新时可能需要重新同步。

二、Firebase推送相关的核心排查点

  • 配置文件校验:确认iOS的GoogleService-Info.plist已通过@react-native-firebase/app插件正确配置,或已放入预构建后的ios/[项目名称]/目录。
  • 推送权限配置:在app.json中添加iOS推送相关权限:
{
  "expo": {
    "ios": {
      "infoPlist": {
        "UIBackgroundModes": ["remote-notification"],
        "NSRemoteNotificationUsageDescription": "需要推送通知接收消息"
      }
    }
  }
}
  • 版本兼容性:当前@react-native-firebase 18.x与Expo 48/RN 0.71.8版本兼容,若仍有问题可尝试锁定到18.2.0等稳定小版本。
  • EAS环境配置:在eas.json中指定匹配的Xcode版本(Expo 48推荐Xcode 14.3.1):
{
  "build": {
    "production": {
      "ios": {
        "xcode": "14.3.1"
      }
    }
  }
}

三、针对性错误处理

根据常见错误场景补充:

  • 若出现Firebase.h找不到的报错,核心原因是未开启模块化头文件,通过上述Podfile添加:modular_headers => true即可解决。
  • 若出现推送证书相关错误,确认EAS Build已关联Apple开发者账号的推送证书,或在Expo Dashboard中正确配置推送密钥。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 14:42:49