RN iOS编译报错:在google命名空间内导入'glog.glog.log_severity'模块
解决RN iOS构建报错:Import of module 'glog.glog.log_severity' appears within namespace 'google'
问题描述
在Xcode构建React Native iOS应用时,触发报错:Import of module 'glog.glog.log_severity' appears within namespace 'google',报错代码位于logging.h的google命名空间片段中:
namespace google { // They need the definitions of integer types. #include "glog/log_severity.h" #include "glog/vlog_is_on.h"
曾尝试在Podfile中添加以下配置(单独或组合使用),但问题未得到解决:
use_modular_headers! pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec', :modular_headers => false pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec', :modular_headers => false pod 'RCT-Folly', :podspec => '../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec', :modular_headers => false
可行解决办法
方法1:修改glog的podspec配置
找到node_modules/react-native/third-party-podspecs/glog.podspec文件,添加以下配置:spec.pod_target_xcconfig = { 'DEFINES_MODULE' => 'NO', 'CLANG_MODULES_AUTOLINK' => 'NO' }保存后执行
pod install,重新构建项目。方法2:调整Xcode模块设置
- 打开Xcode项目,找到Pods项目下的glog目标
- 进入「Build Settings」,搜索「Defines Module」,设置为
NO - 搜索「Enable Modules (C and Objective-C)」,设置为
NO - 执行Cmd+Shift+K清理项目,重新构建
方法3:清理缓存后重装依赖
- 删除项目根目录下的
Pods文件夹和Podfile.lock文件 - 执行
pod deintegrate - 执行
pod install --repo-update - 执行Cmd+Option+Shift+K清理Xcode缓存,重新构建
- 删除项目根目录下的
方法4:调整React Native版本
如果上述方法无效,可尝试将RN版本切换到已知无此问题的版本:- 降级至0.71.x系列
- 升级至0.72.x及以上版本(部分用户反馈新版本已修复该问题)
内容的提问来源于stack exchange,提问作者Morty
相关产品推荐
相关产品推荐

