反应本机 - 找不到'React/RCTBridgeModule.h'文件



我正在尝试在我的反应原生应用程序中使用 react-native-linea,在构建过程中我收到 React/RCTBridgeModule.h' 文件未找到错误。

我尝试的步骤 -

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依赖项才能正常工作。另外,在尝试此操作之前,请确保您在node_modules中提供了软件包react-native-linea

在此解决方案中,您需要为 linea 创建一个 podspec 文件。您可以选择将其保留在ScannerApp项目中,也可以创建原始存储库的分支并将 podspec 文件添加到其中。如果你分叉,请将 podspec 中的 git url 修改为你的存储库 url,并从你的存储库中添加react-native-linea包。这是对我有用的 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

现在你需要在ScannerApppod 文件中将其添加为 cocoapod 依赖项。如果在本地添加 podspec 文件,请确保指定其路径,如下所示,

pod 'LineaPro', :path => '../node_modules/react-native-linea', :podspec => '../ios/LineaPro.podspec'

如果您创建了 fork 并将 podspec 添加到存储库,则跳过:podspec部分。

解决方案 2:直接添加源文件

这是一个相当简单的解决方案,我推荐这个。可以在计算机上本地克隆react-native-linea存储库。

  • DTDevices.hRCTLinea.hRCTLinea.m源文件复制到 ios 项目
  • LineaPro.jsNativeBridges.js复制到 js 项目
  • 将静态库复制到项目libdtdev.a
  • ExternalAccessoryCoreLocation框架和libdtdev.a链接到您的目标

编译并编写 js 代码来初始化 LineaPro 模块。

最新更新