React Native升级后执行pod install报Unknown configuration whitelisted错误
pod install报错解决:Unknown configuration whitelisted: . 问题场景
升级React Native版本后,在iOS目录执行pod install时触发如下错误:
Auto-linking React Native modules for target
<projectname>: RNScreens, RNVectorIcons, and react-native-safe-area-context
[Codegen] Generating ./build/generated/ios/React-Codegen.podspec.json
Analyzing dependencies
Fetching podspec forDoubleConversionfrom../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec
[Codegen] Found FBReactNativeSpec
/Users/belgin/Documents/Apps//node_modules/react-native/scripts/react_native_pods_utils/script_phases.rb:50: warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments.
/Users/belgin/Documents/Apps//node_modules/react-native/scripts/react_native_pods_utils/script_phases.rb:50: warning: Passing trim_mode with the 3rd argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, trim_mode: ...) instead.
Fetching podspec forRCT-Follyfrom../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec
Fetching podspec forboostfrom../node_modules/react-native/third-party-podspecs/boost.podspec
Fetching podspec forglogfrom../node_modules/react-native/third-party-podspecs/glog.podspec
[!] Unknown configuration whitelisted: . CocoaPods found debug and release, did you mean one of these?
当前使用的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, '11.0' install! 'cocoapods', :deterministic_uuids => false target '<ProjectName>' do config = use_native_modules! # Flags change depending on the env values. flags = get_default_flags() use_react_native!( :path => config[:reactNativePath], # to enable hermes on iOS, change `false` to `true` and then install pods :hermes_enabled => flags[:hermes_enabled], :fabric_enabled => flags[:fabric_enabled], # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) target '<ProjectName>' do inherit! :complete # Pods for testing end # Enables Flipper. # # Note that if you have use_frameworks! enabled, Flipper will not work and # you should disable the next line. use_flipper!() post_install do |installer| react_native_post_install(installer) __apply_Xcode_12_5_M1_post_install_workaround(installer) end end
解决方案
1. 清理CocoaPods环境与依赖缓存
进入项目的ios目录,依次执行以下命令:
pod deintegrate rm -rf Podfile.lock rm -rf ../node_modules npm install # 或 yarn install pod install
2. 修复Podfile的嵌套Target命名冲突
Podfile中主Target与内部测试Target使用了相同名称,可能导致配置解析异常。修改内部Target名称为唯一值,例如:
target '<ProjectName>' do # ... 原有代码 ... target '<ProjectName>Tests' do inherit! :complete # Pods for testing end # ... 原有代码 ... end
3. 升级CocoaPods版本
旧版CocoaPods与新版React Native可能存在兼容性问题,执行命令升级:
sudo gem install cocoapods
4. 检查Xcode项目配置
打开Xcode,进入项目的Build Settings -> Configurations,确认仅存在Debug和Release两个有效配置,删除空的或无效的自定义配置。
5. 排查第三方依赖问题
临时禁用某个自动链接的第三方模块(如RNVectorIcons、RNScreens),手动配置后重新执行pod install,逐步定位是否为某一依赖的配置异常导致。
内容的提问来源于stack exchange,提问作者Belgin Jarosh

