React Native升级后Podfile执行pod install报real_path未定义错误
升级React Native后pod install报错
undefined method 'real_path' for nil:NilClass排查与解决 问题场景
升级React Native版本后,执行pod install时触发Podfile崩溃,核心报错为undefined method 'real_path' for nil:NilClass。
环境版本
- Cocoapods: 1.11.3
- Node: 14.17.3
- NPM: 6.14.13
完整错误日志
ios % pod install Auto-linking React Native modules for target `MYAPP`: RNCAsyncStorage, RNCCheckbox, RNCMaskedView, RNDateTimePicker, RNDeviceInfo, RNGestureHandler, RNLocalize, RNSVG, RNScreens, RNVectorIcons, react-native-config, react-native-image-picker, react-native-netinfo, react-native-safe-area-context, react-native-version-check, and rn-fetch-blob [Codegen] Generating ./build/generated/ios/React-Codegen.podspec.json Analyzing dependencies Fetching podspec for `DoubleConversion` from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec` [Codegen] Found FBReactNativeSpec Fetching podspec for `RCT-Folly` from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec` Fetching podspec for `boost` from `../node_modules/react-native/third-party-podspecs/boost.podspec` Fetching podspec for `glog` from `../node_modules/react-native/third-party-podspecs/glog.podspec` Downloading dependencies … installs packages here successfully Generating Pods project [!] An error occurred while processing the post-install hook of the Podfile. undefined method `real_path' for nil:NilClass /Library/Ruby/Gems/2.6.0/gems/xcodeproj-1.22.0/lib/xcodeproj/project/object/container_item_proxy.rb:96:in `container_portal_annotation' /Library/Ruby/Gems/2.6.0/gems/xcodeproj-1.22.0/lib/xcodeproj/project/object/container_item_proxy.rb:105:in `to_hash_as' /Library/Ruby/Gems/2.6.0/gems/xcodeproj-1.22.0/lib/xcodeproj/project/object.rb:421:in `to_ascii_plist' /Library/Ruby/Gems/2.6.0/gems/xcodeproj-1.22.0/lib/xcodeproj/project.rb:298:in `block in to_ascii_plist' /Library/Ruby/Gems/2.6.0/gems/xcodeproj-1.22.0/lib/xcodeproj/project.rb:296:in `each' /Library/Ruby/Gems/2.6.0/gems/xcodeproj-1.22.0/lib/xcodeproj/project.rb:296:in `to_ascii_plist' /Library/Ruby/Gems/2.6.0/gems/xcodeproj-1.22.0/lib/xcodeproj/project.rb:365:in `block in save' /Library/Ruby/Gems/2.6.0/gems/atomos-0.1.3/lib/atomos.rb:21:in `block in atomic_write' /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tempfile.rb:295:in `open' /Library/Ruby/Gems/2.6.0/gems/atomos-0.1.3/lib/atomos.rb:17:in `atomic_write' /Library/Ruby/Gems/2.6.0/gems/xcodeproj-1.22.0/lib/xcodeproj/project.rb:364:in `save' /Users/MyUser/dev/MYAPPV2/node_modules/react-native/scripts/cocoapods/utils.rb:71:in `block in exclude_i386_architecture_while_using_hermes' /Users/MyUser/dev/MYAPPV2/node_modules/react-native/scripts/cocoapods/utils.rb:66:in `each' /Users/MyUser/dev/MYAPPV2/node_modules/react-native/scripts/cocoapods/utils.rb:66:in `exclude_i386_architecture_while_using_hermes' /Users/MyUser/dev/MYAPPV2/node_modules/react-native/scripts/react_native_pods.rb:161:in `react_native_post_install' /Users/MyUser/dev/MYAPPV2/ios/Podfile:17:in `block (3 levels) in from_ruby' /Library/Ruby/Gems/2.6.0/gems/cocoapods-core-1.11.3/lib/cocoapods-core/podfile.rb:196:in `post_install!' /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:945:in `run_podfile_post_install_hook' /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:933:in `block in run_podfile_post_install_hooks' /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:149:in `message' /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:932:in `run_podfile_post_install_hooks' /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:331:in `block (2 levels) in create_and_save_projects' /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/pods_project_generator/pods_project_writer.rb:61:in `write!' /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:330:in `block in create_and_save_projects' /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:64:in `section' /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:309:in `create_and_save_projects' /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:301:in `generate_pods_project' /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:180:in `integrate' /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:167:in `install!' /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/command/install.rb:52:in `run' /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run' /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:52:in `run' /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/bin/pod:55:in `<top (required)>' /usr/local/bin/pod:23:in `load' /usr/local/bin/pod:23:in `<main>' [!] `<PBXGroup name=`Libraries` UUID=`832341AE1AAA6A7D00B99B32`>` attempted to initialize an object with an unknown UUID. `65A7A9B869DB4D1CB5659E12` for attribute: `children`. This can be the result of a merge and the unknown UUID is being discarded. [!] `<PBXProject name=`MYAPP` UUID=`83CBB9F71A601CBA00E9B192`>` attempted to initialize an object with an unknown UUID. `65A7A9B869DB4D1CB5659E12` for attribute: `project_references`. This can be the result of a merge and the unknown UUID is being discarded.
当前Podfile内容
require_relative '../node_modules/react-native/scripts/react_native_pods' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' platform :ios, '12.4' install! 'cocoapods', :deterministic_uuids => false target 'MyApp' do config = use_native_modules! use_react_native!( :path => config[:reactNativePath], :hermes_enabled => true, :fabric_enabled => flags[:fabric_enabled], :flipper_configuration => FlipperConfiguration.enabled, :app_path => "#{Pod::Config.instance.installation_root}/.." ) pod 'RNSVG', :path => '../node_modules/react-native-svg' pod 'CocoaAsyncSocket' post_install do |installer| react_native_post_install(installer, :mac_catalyst_enabled => false) __apply_Xcode_12_5_M1_post_install_workaround(installer) installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings["ONLY_ACTIVE_ARCH"] = "NO" end end end end
解决步骤
1. 清理缓存与冗余文件
执行以下命令彻底清理现有依赖与缓存:
cd ios rm -rf Pods Podfile.lock rm -rf ../node_modules package-lock.json npm install pod deintegrate pod clean
2. 修改Podfile
移除过时的Xcode补丁,调整use_react_native!参数,修复后的Podfile如下:
require_relative '../node_modules/react-native/scripts/react_native_pods' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' platform :ios, '12.4' install! 'cocoapods', :deterministic_uuids => false target 'MyApp' do config = use_native_modules! use_react_native!( :path => config[:reactNativePath], :hermes_enabled => true, :fabric_enabled => flags[:fabric_enabled], :flipper_configuration => FlipperConfiguration.enabled ) pod 'RNSVG', :path => '../node_modules/react-native-svg' pod 'CocoaAsyncSocket' post_install do |installer| react_native_post_install(installer, :mac_catalyst_enabled => false) installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings["ONLY_ACTIVE_ARCH"] = "NO" end end end end
- 移除了
__apply_Xcode_12_5_M1_post_install_workaround:该补丁仅针对Xcode 12.5的M1设备问题,若当前Xcode版本更高则无需保留 - 删除了
:app_path参数:让React Native自动识别项目路径,避免路径引用错误
3. 修复Xcode项目引用冲突
打开Xcode:
- 找到Libraries目录,删除其中无效的红色引用
- 执行
Cmd+Shift+K清理Build文件,Cmd+Option+Shift+K清理派生数据
4. 重新执行pod install
pod install --repo-update
问题根源说明
该错误主要由升级RN后以下因素导致:
- 旧Pod缓存与新版本RN的post_install脚本逻辑冲突
- Xcode项目中残留无效的引用UUID
- 过时的Xcode补丁与当前环境不兼容
内容的提问来源于stack exchange,提问作者Mike Upjohn
相关产品推荐
相关产品推荐

