Azure DevOps构建React Native新架构iOS时pod install失败求助
解决React Native 0.76新架构在Azure DevOps中pod install的栈溢出问题
问题重现
React Native升级至0.76新架构后,本地Mac可正常构建,但Azure DevOps执行pod install时抛出栈溢出错误:
bundler: failed to load command: pod (/Users/runner/work/1/s/vendor/bundle/ruby/3.3.0/bin/pod) SystemStackError: stack level too deep /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/stub_specification.rb:230:in `loaded_spec' /usr/local/lib/ruby/site_ruby/3.3.0/rubygems/stub_specification.rb:186:in `spec'
使用的依赖版本:
- activesupport 7.0.8.6
- ruby 3.3.0
- algoliasearch 1.27.5
- cocoapods-core 1.14.3
可行解决方案
1. 增大Ruby栈大小并清理Bundle缓存
当前设置的RUBY_THREAD_VM_STACK_SIZE=1000000可能不足以应对新架构下的依赖解析,同时CI环境的bundle缓存可能存在损坏或冲突。修改脚本如下:
- script: | export RUBY_THREAD_VM_STACK_SIZE=2000000 export RCT_NEW_ARCH_ENABLED=1 bundle clean --force bundle install --deployment bundle exec pod install displayName: 'iOS | CocoaPods packages installing with new architecture' workingDirectory: '$(Build.SourcesDirectory)/ios' condition: ne(variables['cache_pods_restored'], 'true')
- 增大栈大小到2000000,避免递归解析时栈溢出
- 添加
bundle clean --force清理旧缓存,确保依赖完全重新安装 - 使用
bundle install --deployment严格按Gemfile.lock安装依赖,避免版本漂移
2. 锁定Ruby与CocoaPods版本匹配本地环境
本地构建正常说明本地依赖版本组合兼容,需确保CI环境完全对齐:
- 在项目根目录添加
.ruby-version文件,指定Ruby版本:3.3.0 - 在iOS目录的Gemfile中明确指定CocoaPods版本,与本地一致:
gem 'cocoapods', '1.14.3' - Azure DevOps脚本中添加Ruby版本管理步骤(以rbenv为例):
- script: | brew install rbenv ruby-build rbenv install 3.3.0 rbenv global 3.3.0 echo 'eval "$(rbenv init -)"' >> ~/.bash_profile source ~/.bash_profile displayName: 'Install and configure Ruby 3.3.0'
3. 规避Ruby 3.3.0与旧Gem的兼容性问题
Ruby 3.3.0的内部规范处理逻辑有变化,与部分旧版本Gem(如activesupport 7.0.8.6)存在递归调用冲突。可以:
- 将activesupport升级至7.1.x版本(兼容Ruby 3.3),修改Gemfile后运行
bundle update activesupport - 暂时降级Ruby版本至3.2.x,在
.ruby-version中指定3.2.2,同时调整CI脚本安装对应版本
原因分析
该错误属于Ruby栈溢出,核心诱因是:
- Ruby 3.3.0与CocoaPods 1.14.3/activesupport 7.0.8.6的兼容性问题,导致
rubygems/stub_specification.rb中的递归调用超出栈限制 - CI环境的bundle缓存未完全清理,残留的旧依赖与新架构需求冲突
- 默认的Ruby栈大小不足以支撑新架构下更复杂的依赖解析逻辑
内容的提问来源于stack exchange,提问作者Hoang Hai
相关产品推荐
相关产品推荐

