升级到RN 0.66和Xcode13后构建iOS应用提示'gtest/gtest.h'找不到如何解决
问题描述
将RN从0.61.5版本升级到0.66版本、Xcode从12版本升级到13版本后,无法在Xcode中正常构建iOS应用。Podfile配置如下:
platform :ios, '11.0' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' target 'strongauthappreact' do # Pods for strongauthappreact pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector" # pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec" pod 'FBReactNativeSpec', :path => "../node_modules/react-native/React/FBReactNativeSpec" pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired" pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety" pod 'React', :path => '../node_modules/react-native/' pod 'React-Core', :path => '../node_modules/react-native/' pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules' pod 'React-Core/DevSupport', :path => '../node_modules/react-native/' pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS' pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation' pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob' pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image' pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS' pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network' pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings' pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text' pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration' pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/' pod 'boost', :podspec => '../node_modules/react-native/third-party-podspecs/boost.podspec' pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact' pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi' pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor' pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector' # pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon" pod 'React-callinvoker', :path => "../node_modules/react-native/ReactCommon/callinvoker" pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon" pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga' pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec' pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' # pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' pod 'RCT-Folly', :podspec => '../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec' pod 'React-perflogger', :podspec => '../node_modules/react-native/ReactCommon/reactperflogger' pod 'React-logger', :podspec => '../node_modules/react-native/ReactCommon/logger' pod 'React-runtimeexecutor', :podspec => '../node_modules/react-native/ReactCommon/runtimeexecutor' permissions_path = '../node_modules/react-native-permissions/ios' pod 'Permission-Camera', :path => "#{permissions_path}/Camera.podspec" pod 'RNI18n', :path => '../node_modules/react-native-i18n' pod 'react-native-randombytes', :path => '../node_modules/react-native-randombytes' pod 'jail-monkey', :path => '../node_modules/jail-monkey' pod 'react-native-config', :path => '../node_modules/react-native-config' pod 'react-native-splash-screen', :path => '../node_modules/react-native-splash-screen' pod 'RNExitApp', :path => '../node_modules/react-native-exit-app' pod 'react-native-sqlite-storage', :path => '../node_modules/react-native-sqlite-storage' pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons' pod 'TrustKit' pod 'Folly-GTest', '~> 1.10' pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage' use_native_modules! end
遇到的报错信息为:
'gtest/gtest.h' file not found
已尝试重置Metro缓存、清理$TMPDIR目录、删除node_modules文件夹、删除Pods文件夹、重新安装所有依赖、清理Xcode构建缓存等操作,问题仍未解决。
解决方案
- 第一步:删除Podfile中
pod 'Folly-GTest', '~> 1.10'这一行。RN 0.64及以上版本已经将RCT-Folly的GTest依赖做了内置处理,不需要手动额外引入,手动引入的Folly-GTest版本和RN 0.66依赖的RCT-Folly版本不兼容,是触发头文件找不到的核心原因。 - 第二步:同步将Podfile第一行的iOS最低版本声明修改为
platform :ios, '12.0',RN 0.66版本官方要求最低支持iOS 12.0,原11.0的配置会引发其他潜在兼容问题。 - 第三步:进入项目ios目录,执行以下命令重新安装Pod依赖:
pod cache clean --all rm -rf Podfile.lock Pods *.xcworkspace pod install --repo-update - 第四步:打开新生成的
.xcworkspace文件,在Xcode中按Command + Shift + K清理构建缓存后重新执行构建即可。
内容的提问来源于stack exchange,提问作者shogitai
相关产品推荐
相关产品推荐

