2

I am trying to use react-native-linea in my react native app and during build I am getting React/RCTBridgeModule.h' file not found error.

Steps I tried -

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 **
Nimantha
  • 6,405
  • 6
  • 28
  • 69
user3807000
  • 21
  • 1
  • 2
  • Step 4 seems unnecessary since you do manual installation in steps 5, 6, 7 anyways. React native link will try to install native module as cocoapods if podspec exists, but then you need to setup React from cocoapod as well. Try again without step 4. – Amar Jul 11 '19 at 02:59
  • I tried without step4 and getting same error. Also tried -- https://stackoverflow.com/questions/53854008/react-native-xcode-header-files-not-being-found-rctbridgemodule and https://facebook.github.io/react-native/docs/linking-libraries-ios – user3807000 Jul 12 '19 at 06:06

1 Answers1

1

Solution 1: Adding podspec

Prerequisite: You will need to setup React as cocoapod dependency for this to work. Also, before you try this make sure you have package react-native-linea available in node_modules.

In this solution you need to create a podspec file for the linea. You can choose to keep it in your ScannerApp project or fork the original repo and add the podspec file to it. If you fork, please modify the git urls in the podspec to your repo url and add the react-native-linea package from your repo. Here's the podspec that worked for me,

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

Now you need to add this as cocoapod dependency in your ScannerApp podfile. If you add podspec file locally, make sure to specify its path as below,

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

If you created fork and added podspec to repo then skip the :podspec part.

Solution 2: Add source files directly

This is fairly simple solution and i'd recommend this. You can clone the react-native-linea repo locally on your machine.

  • Copy DTDevices.h, RCTLinea.h, RCTLinea.m source files to ios project
  • Copy LineaPro.js, NativeBridges.js to js project
  • Copy libdtdev.a static lib to project
  • Link ExternalAccessory, CoreLocation frameworks and libdtdev.a to your target

Compile and write js code to initialize LineaPro module.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Amar
  • 13,202
  • 7
  • 53
  • 71