reactjs - Reactnative - 'React/RCTBridgeModule.h' 文件未找到
问题描述
我正在尝试在我的 react native 应用程序中使用 react-native-linea,并且在构建期间我收到 React/RCTBridgeModule.h' file not found 错误。
我试过的步骤 -
1. react-native init ScannerApp
2. cd ScannerApp/
3. npm i react-native-linea --save
4. react-native link react-native-linea
5.Drag and drop the InfineaSDK Framework into the General > Embedded Binaries section of your Project. The framework will also display the Linked Frameworks and Libraries.
a. Verify that Copy Items if needed is checked.
6.Add the following to General > Linked Frameworks and Libraries:
• CoreLocation.framework
• ExternalAccessory.framework
• Foundation.framework
7.Add a new Run Script phase.
At the end of your project’s Build phase(s), add new running scripts to set up InfineaSDK.
FRAMEWORKS="${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}" "${FRAMEWORKS}/InfineaSDK.framework/SDKSetup"
8.react-native run-ios
****Error*****
simulator/react-native-linea.build/Objects-normal/x86_64/RCTLinea.o
In file included from /Users/****/reactnative/ScannerApp/node_modules/react-native-linea/react-native-linea/RCTLinea.m:9:
/Users/****/reactnative/ScannerApp/node_modules/react-native-linea/react-native-linea/RCTLinea.h:9:9: fatal error: 'React/RCTBridgeModule.h' file not found
#import <React/RCTBridgeModule.h>
^~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
** BUILD FAILED **
解决方案
解决方案 1:添加 podspec
先决条件:您需要将 React 设置为 cocoapod 依赖项才能正常工作。此外,在您尝试此操作之前,请确保您有react-native-linea
可用的node_modules
.
在此解决方案中,您需要为 linea 创建一个 podspec 文件。您可以选择将其保留在您的ScannerApp
项目中,或者 fork 原始 repo 并将 podspec 文件添加到其中。如果你 fork,请将 podspec 中的 git url 修改为你的 repo url,并react-native-linea
从你的 repo 中添加包。这是对我有用的 podspec,
require 'json'
package = JSON.parse(File.read(File.join(__dir__, '../node_modules/react-native-linea/package.json')))
Pod::Spec.new do |s|
s.name = 'LineaPro'
s.version = package['version']
s.summary = package['description']
s.license = package['license']
s.homepage = 'https://github.com/pablo-coco/react-native-linea'
s.authors = 'pablo-coco'
s.source = { :git => 'https://github.com/pablo-coco/react-native-linea.git', :tag => s.version }
s.source_files = '*.{h,m}','react-native-linea/*.{h,m}'
s.requires_arc = true
s.platforms = { :ios => "9.0" }
s.vendored_libraries = 'libdtdev.a'
s.frameworks = 'ExternalAccessory', 'CoreLocation'
s.dependency 'React'
end
现在您需要将其作为 cocoapod 依赖项添加到您的ScannerApp
podfile 中。如果您在本地添加 podspec 文件,请确保指定其路径,如下所示,
pod 'LineaPro', :path => '../node_modules/react-native-linea', :podspec => '../ios/LineaPro.podspec'
如果您创建了 fork 并将 podspec 添加到 repo,则跳过该:podspec
部分。
方案二:直接添加源文件
这是相当简单的解决方案,我会推荐这个。react-native-linea
您可以在您的机器上本地克隆repo。
- 复制
DTDevices.h
,RCTLinea.h
,RCTLinea.m
源文件到 ios 项目 - 复制
LineaPro.js
,NativeBridges.js
到 js 项目 - 将
libdtdev.a
静态库复制到项目 - 链接
ExternalAccessory
、CoreLocation
框架和libdtdev.a
目标
编译编写js代码初始化LineaPro模块。
推荐阅读
- python-3.x - 如何检查空列表是否在列表内的字典内并从列表中删除该字典对象?
- php - 如何在PHP中删除字符串中的重复字母
- java - 单击不同片段上的视图时如何触发“BottomSheet”展开?
- c# - 正则表达式的数据验证
- python - Python asyncio 跳过处理直到函数返回
- logging - .Net Core 2.1 Logging Provider - 我应该维护记录器实例吗?
- rest - 集成测试中的空 WebApplicationContext
- bootstrap-vue - bootstrap-vue 切换导航在单击时不删除样式属性
- facebook-payments - 了解 Facebook 支付的履行流程
- javascript - 从嵌套的json为jasmine-data-provider赋值?