React/RCTDefines.h' 文件未找到 (RN0.61)

React/RCTDefines.h' file not found (RN0.61)

执行了从 RN0.60 到 RN0.61 的 RN 升级。由于以下问题,构建失败 iOS:

/react-native/React/Base/RCTBridgeModule.h:10:9: 'React/RCTDefines.h' file not found

我知道这个 breaking changes。 (React.xcodeproj 已弃用)

尝试一些事情

  1. npx react-native-clean-project & 重新设置项目
  2. 删除 Pods/ & pod 安装
  3. ...运行 没脑子...

这是我的播客文件的样子。

  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/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 '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 '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'

  # Required by RNFirebase
  pod 'Firebase/Core', '~> 6.9.0'
  pod 'RNFirebase', :path => '../node_modules/react-native-firebase/ios'
  pod 'Fabric', '~> 1.10.2'
  pod 'Crashlytics', '~> 3.14.0'

  # FBSDK
  pod 'react-native-fbsdk', :path => '../node_modules/react-native-fbsdk'

  pod 'react-native-netinfo', :path => '../node_modules/@react-native-community/netinfo'
  pod 'react-native-image-picker', :path => '../node_modules/react-native-image-picker'
  pod 'react-native-splash-screen', :path => '../node_modules/react-native-splash-screen'
  pod 'react-native-webview', :path => '../node_modules/react-native-webview'

我前段时间遇到过同样的问题。它在以下之后得到修复:product > scheme > edit scheme,转到构建选项卡并将 react 添加为第一个目标。

这是我花了一整天时间挖掘原因后的解决方案,
.
.
.
.

TLDR;

您需要为抱怨找不到 React/{whatever.h}[=18= 的第 3 个 party/custom 库添加 .podspec 到 podfile ]


第三方库

如果您使用的是第三方库 (Yarn/NPM/etc)

  1. 从其他第 3 方库复制 podspec(例如,RNDeviceInfo/etc..)

  2. 通过替换一些项目创建自己的 podspec (s.name, s.source) 我实际上将其他项目保留为默认值,但您可以根据自己的使用情况进行修改如果你想要

s.name         = "NoSupportedLib"
s.source       = { :git => "https://github.com/react-native-community/NoSupportedLibName.git", :tag => "v#{s.version}" }

您可能需要注意以下事项,因为并非所有依赖项都可能存储在文件夹路径下 ios/**/your.m & your.h files

s.source_files  = "ios/**/*.{h,m}"
  1. 向 podfile 添加新行 pod 'NoSupportedLib', :path => '../node_modules/NoSupportedLib'

  2. Pod 安装

本地依赖

如果您有 本地依赖项,您也应该这样做(而不是将 .a 文件添加到 Xcode 的链接中框架和库。)

  1. 按照上面描述的相同步骤进行操作
  2. 在第 2 步声明 s.source & s.source_files 时,您应执行以下操作:(假设您同时创建此 custom.podspec自定义库路径,否则您需要根据需要修改 s.source 路径)
s.source            = { :http => 'file:' + __dir__ + '/' }
s.source_files  = "customLib/*.{h,m}"
  1. 向 podfile 添加新行
pod 'customLib', :path => '../localDependency/customLib'


分点

我尝试在我的方案下添加 React 作为构建目标,显然它没有帮助。我认为对于 >=RN0.60 的项目,我们应该使用 ReactNative 提供的 autolinking 吗?因此,为了保持我们 Xcode 的链接框架和库的清洁。

我遇到了同样的问题,我进入 /node_modules/react-native/React/Base/RCTBridgeModule.h 并将 #import 更改为

#if __has_include("RCTDefines.h")
  #import "RCTDefines.h"
#else
 #import <React/RCTDefines.h>
#endif

参考低于 link

https://github.com/facebook/react-native/issues/26754#issuecomment-539550146