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

时间:2019-07-10 21:30:50

标签: reactjs xcode react-native react-native-ios linea-pro

我试图在我的本机应用程序中使用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 个答案:

答案 0 :(得分:0)

解决方案1:添加podspec

先决条件:您需要将React设置为cocoapod依赖项才能起作用。另外,在尝试执行此操作之前,请确保在react-native-linea中有可用的软件包node_modules

在此解决方案中,您需要为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

现在,您需要在ScannerApp Podfile中将此添加为cocoapod依赖项。如果您在本地添加podspec文件,请确保按以下方式指定其路径,

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

如果您创建了fork并将podspec添加到了repo,请跳过:podspec部分。

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

这是一个非常简单的解决方案,我建议这样做。您可以在计算机上本地克隆react-native-linea存储库。

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

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

希望有帮助!