升级React Native至0.72.6后Podfile出现config未定义错误
解决React Native 0.72.6升级后
pod install报错undefined local variable or method 'config'的方案 问题根源
报错来自Podfile的post_install代码块中未正确定义或引用config变量,React Native 0.70+版本的Podfile结构发生变化,旧版本的配置写法不再适配。
具体修改步骤
- 定位问题代码:打开
ios/Podfile,找到第109行所在的post_install代码块。 - 修正参数传递:
- 确保
post_install块接收installer参数,写法应为:post_install do |installer| # 你的配置代码 end - 若遍历
build_configurations时未传入config变量,补上参数定义:
错误写法:
修正为:target.build_configurations.each do config.build_settings[...] = ... endtarget.build_configurations.each do |config| config.build_settings[...] = ... end
- 确保
- 添加RN必需的后置处理:在
post_install块末尾添加React Native 0.70+要求的配置处理:react_native_post_install(installer)
示例修正后的post_install块
post_install do |installer| # 自定义配置示例:修改部署目标版本 installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0' end end # RN 0.70+必需的后置处理 react_native_post_install(installer) end
验证操作
修改完成后执行以下命令重新安装依赖:
pod install --repo-update
内容的提问来源于stack exchange,提问作者Florin Dobre
相关产品推荐
相关产品推荐

