React Native 0.59旧项目在macOS Sonoma中Pod安装报错求助
React Native 0.59 项目在 macOS Sonoma 上 pod install 失败的解决方案
问题背景
React Native 0.59 项目在 macOS Sonoma 系统执行 pod install 时失败,Podfile 内容如下:
# Uncomment the next line to define a global platform for your project # platform :ios, '9.0' target 'WhizzTanzania' do # Uncomment the next line if you're using Swift or would like to use dynamic frameworks # use_frameworks! # Pods for WhizzTanzania pod 'XCDYouTubeKit', '~> 2.6' pod 'Firebase/Core', '~> 5.20.1' pod 'Firebase/Messaging', '~> 5.20.1' pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info' pod 'react-native-geocoder', :path => '../node_modules/react-native-geocoder' pod 'Alamofire' pod 'RNI18n', :path => '../node_modules/react-native-i18n' end
报错核心原因是旧版本依赖与 macOS Sonoma、新版 Xcode 的兼容性冲突,包括 Ruby 版本不匹配、第三方库未适配新系统 SDK 等。
具体解决步骤
1. 适配 Ruby 与 CocoaPods 版本
RN 0.59 仅兼容 CocoaPods 1.8.x 版本,而 macOS Sonoma 自带的 Ruby 3.x 会导致安装失败,需降级 Ruby:
- 用 Homebrew 安装 rbenv:
brew install rbenv - 安装 Ruby 2.7.8(兼容旧版 CocoaPods 的最高稳定版):
rbenv install 2.7.8 - 在项目根目录设置本地 Ruby 版本:
rbenv local 2.7.8 - 安装指定版本 CocoaPods:
gem install cocoapods -v 1.8.4
2. 更新 Podfile 配置
修改 Podfile 如下:
# 指定兼容的 iOS 版本 platform :ios, '11.0' target 'WhizzTanzania' do # 开启动态框架以适配部分新依赖 use_frameworks! # Pods for WhizzTanzania # 升级 XCDYouTubeKit 到兼容新系统的版本 pod 'XCDYouTubeKit', '~> 2.12.0' # 保留原有 Firebase 版本(若升级需同步 RN 对应插件版本) pod 'Firebase/Core', '~> 5.20.1' pod 'Firebase/Messaging', '~> 5.20.1' # 锁定 RNDeviceInfo 到与 RN 0.59 兼容的版本 pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info', :version => '2.1.5' # 替换 react-native-geocoder 为社区兼容分支 pod 'react-native-geocoder', :git => 'https://github.com/devfd/react-native-geocoder.git', :branch => 'master' # 指定 Alamofire 兼容版本 pod 'Alamofire', '~> 5.8.1' pod 'RNI18n', :path => '../node_modules/react-native-i18n' end
3. 清理缓存并重新安装
执行以下命令彻底清理后重新安装:
# 删除旧的锁文件和 pods 目录 rm Podfile.lock && rm -rf Pods # 清理 CocoaPods 缓存 pod cache clean --all # 更新仓库并安装依赖 pod install --repo-update
4. 调整 Xcode 项目设置
打开 iOS 项目文件(.xcworkspace),修改以下设置:
- 将项目
Deployment Target调整为 iOS 11.0 - 在
Build Settings中,将Build Active Architecture Only设置为YES(仅 Debug 模式) - 关闭
Bitcode(旧依赖普遍不支持)
内容的提问来源于stack exchange,提问作者Harshal Kalavadiya
相关产品推荐
相关产品推荐

