我正在尝试将 native 依赖项添加到 react native 的空白 Expo 项目中。在 Xcode 中构建后,我不断收到此错误:‘React/RCTBridge.h’ file not found
。我想使用的特定库是 react-native-camera
,但我尝试过其他库,但它们也无法正确链接。我可以让库与使用 react-native-init
创建的项目正确链接和create-react-native-app
(已分离)。以下是我创建和分离 expo 项目所采取的步骤:
编辑(对于不同类型的链接,我执行了不同的步骤 4,5 和 8)
- 我创建了一个新的 exp 项目。
- 我将以下内容添加到我的 app.json 中:
"ios": { "bundleIdentifier": "com.yourcompany.yourappname", "supportsTablet": true }, "android": { "package": "com.yourcompany.yourappname" }
exp detach
npm i <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0b796e6a687f26656a7f627d6e26686a666e796a4b3b253d" rel="noreferrer noopener nofollow">[email protected]</a> --save
-
react-native link
-
npm i
-
cd ios
-
pod install
-
exp start
我尝试了以下解决方案(A、B、C):
A.来自:react-native-camera's docs 1) 大多数情况下使用 CocoaPods 自动安装 2)手动安装
B.来自:the expo docs
because react-native link is not aware of CocoaPods, it may not do a complete job installing your dependency. If you encounter build issues locating the headers, you may need to manually add Pods/Headers/Public to the Header Search Paths configuration for your native dependency in Xcode...The target you care to configure is the one created by react-native link inside your Xcode project. You’ll want to determine the relative path from your library to Pods/Headers/Public
C.最后,我尝试了 This answer from stackoverflow
最佳答案
$(SRCROOT) 指的是 native 模块的源文件夹,而不是整个项目的顶级根目录。
我必须根据我引入的 native 模块的位置(在node_modules下)使用$(SRCROOT)/../../../ios/Pods/Headers/Public。
关于react-native - 无法使用 Xcode (React-Native) 将 native 包添加到分离的 Expo 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45115008/