Expo项目iOS构建报错:React Native Firebase Selector未找到
Expo iOS构建报错:react-native-firebase RemoteConfig API兼容问题
错误信息
❌ (node_modules/react-native-firebase/ios/RNFirebase/config/RNFirebaseRemoteConfig.m:52:86) 50 | 51 | RCT_EXPORT_METHOD(enableDeveloperMode) { > 52 | FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:YES]; | ^ no visible @interface for 'FIRRemoteConfigSettings' declares the selector 'initWithDeveloperModeEnabled:' 53 | [FIRRemoteConfig remoteConfig].configSettings = remoteConfigSettings; 54 | } 55 | ❌ (node_modules/react-native-firebase/ios/RNFirebase/config/RNFirebaseRemoteConfig.m:87:51) 85 | rejecter: 86 | (RCTPromiseRejectBlock) reject) { > 87 | BOOL status = [[FIRRemoteConfig remoteConfig] activateFetched]; | ^ no visible @interface for 'FIRRemoteConfig' declares the selector 'activateFetched' 88 | resolve(@(status)); 89 | } 90 |
项目版本
react-native: 0.68.2expo: ~45.0.0react-native-firebase: ^5.6.0@react-native-firebase/app: ^16.4.6@react-native-firebase/messaging: ^16.4.6- Xcode: 14.1
问题原因
- 版本冲突:同时安装了旧版全局
react-native-firebase(v5.6.0)和新版模块化@react-native-firebase系列包(v16.4.6),二者属于不同迭代阶段的包,无法兼容共存。 - API废弃:Xcode 14.1对应Firebase SDK版本较高,旧版
react-native-firebase使用的RemoteConfig API在新版Firebase SDK中已被移除:initWithDeveloperModeEnabled:被替换为通过FIRRemoteConfigSettings的属性配置开发者模式activateFetched被替换为新的激活方法
解决方案
1. 统一Firebase依赖包
卸载旧版全局react-native-firebase,仅保留新版模块化包:
# npm npm uninstall react-native-firebase # yarn yarn remove react-native-firebase
如果需要使用RemoteConfig功能,安装对应新版包:
# npm npm install @react-native-firebase/remote-config # yarn yarn add @react-native-firebase/remote-config
2. 适配新版RemoteConfig API
替换代码中旧版API调用:
- 启用开发者模式:
import remoteConfig from '@react-native-firebase/remote-config'; // 替代原enableDeveloperMode方法 await remoteConfig().setConfigSettings({ developerModeEnabled: true, });
- 激活已获取的配置:
// 替代原activateFetched方法 const isActivated = await remoteConfig().activate(); resolve(isActivated);
3. 清理并重新构建
# 清除依赖缓存 npm cache clean --force # 或 yarn cache clean # 删除依赖文件 rm -rf node_modules package-lock.json yarn.lock # 重新安装依赖 npm install # 或 yarn install # Expo项目清理原生代码并重新生成 expo prebuild --clean
之后用Xcode重新执行构建即可。
内容的提问来源于stack exchange,提问作者charlie2
相关产品推荐
相关产品推荐

