2

我正在尝试在我的 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 **
4

1 回答 1

1

解决方案 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 依赖项添加到您的ScannerApppodfile 中。如果您在本地添加 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静态库复制到项目
  • 链接ExternalAccessoryCoreLocation框架和libdtdev.a目标

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

于 2019-07-12T07:25:41.857 回答