Native Module cannot be null - when integrating react-native project inside another react-native project - react-native

I have a react-native cross platform project based on Underdark library for exchanging data using Bluetooth and Wifi. this is working as react-native project. I am able to transfer data between iPhone and android.
Now i want to integrate this into another react native project as a package or use it in another project. But the private Underdark react native project is not a proper package in itself. It is just a working react native project.
I have integrated by using the following commands.
npm install —save
In Xcode I have imported the project and added the libraries/framework (underdark and protocol buffers ) into Build phases.
On the react side the entire project gets installed under node-modules.
Now i create a component and import the files in underdark library in node modules.
I run the react-native run-ios command to run it on my device.
It builds successfully but gives the following error.
2017-06-29 12:31:27.406 [error][tid:com.facebook.react.JavaScript] Native module cannot be null.
2017-06-29 12:31:27.523 [error][tid:com.facebook.react.JavaScript] Module AppRegistry is not a registered callable module (calling runApplication)
My question is
Is it possible to use a react native project in another project as a third party library. even if it is not a package.
How to remove this error.

Related

Using highcarts in react native and getting the error

I have installed npm install #highcharts/highcharts-react-native in my react native project and i also added the hcscript in metro.config.js file.
Iam getting the error of
Failed to fetch scripts or layout. The method or property expo-file-system.readDirectoryAsync is not available on android, are you sure you've linked all the native dependencies properly?
if you wanted to use this package: #highcharts/highcharts-react-native you should first install react-native-unimodules which is a set of native dependencies used at the core of #highcharts/highcharts-react-native as
they built the package on top of expo not bare react native.
it is going to require you to make heavy edits in the native ios and android files such as appDelegate.m in ios and more alike files.
However, you should notice this package is deprecated as per the official page, and there is no reliable alternative!

How to link native library to react native application and what is the folder structure?

I am trying to build simple app to creative native library and link with react native app.
I am facing issue like
Error : Unable to resolve module react-native-fingerprint from App.js: react-native-fingerprint could not be found within the project.
Note : 'react-native-fingerprint' which is been created and want to link with app.
I guess you're using react-native-fingerprint-scanner. Since library you mentioned doesn't exist.
In case if you using this library react-native-fingerprint-scanner.
Installation
npm install react-native-fingerprint-scanner --save
or
yarn add react-native-fingerprint-scanner
Link to Native Platforms
react-native link react-native-fingerprint-scanner
Even after this it is not working. Following this guide

What is the right way to import custom react native module on Xcode?

I'm building a custom RN module for iOS and Android. Following some others modules, I notice that the dependencies it's never imported to the module itself, but always imported in the main app. For example for iOS:
react-native-admob has Google Mobile Ads SDK as dependency, but the developer has to add on the app.
That said, I have my custom module only building on Xcode, because when I try to run react-native run-ios I get the error:
info In file included from /Users/.../node_modules/react-native-my-module/ios/MyModuleViewManager.m:2:
/Users/.../node_modules/react-native-my-module/ios/RNMyModule.h:8:9: fatal error: module 'PrebidMobile' not found
#import PrebidMobile;
~~~~~~~^~~~~~~~~~~~
error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening myapp.xcworkspace
What could I be doing wrong, that react-native command can't find the import library from Link Binary With Libraries?

When to use react-native link?

I understand that react-native link (see post) is an automatic way to install native dependencies. The post above explain how to use the link command but lacking the detail of when to use it. Should it be used after adding a component, every code change or after introducing new module to the app?
Why we use react-native-link??
In this post, I will explain why we use react native link command and when we need to use this command or not?
First, we will understand what is native module??
Native Modules
Native modules are usually distributed as npm packages, apart from the typical javascript files and resources they will contain an Android and ios library project. 
React Native provides an impressive amount of native modules that give you direct access to core platform APIs on both Android and IOS.
For example react-native-maps, react-native-firebase, react-native-socketio etc.
These modules or packages contained both platform (Android and Ios) code.
Now coming on to the react native link
Those libraries which are use native code, in that case you'll have to add these files to your app. For linking those library with react native code need to run react-native-link
Here are the few steps to link your libraries that contain native code
Automatic linking
Step 1
Install a library with native dependencies:
$ npm install --save
Step 2
Link your native dependencies:
$ react-native link
Done! All libraries with native dependencies should be successfully linked to your iOS/Android project.
Where we don't use react-native-link??
Those components which are only written in javascript they are not using any native code (Android and Ios). There is no need to run react-native-link.
For example rn-modal-picker, react-native-check-box etc.
You should check out this other answer: The use of react-native-link command?
You only need to run react-native link NAME_OF_PACKAGE when you install a new package that has a native codebase, or without arguments if you want to do it for multiple of them.

How to import existing project in expo?

I have a project which developed in react native using expo tool. Now I am trying to import project in expo but facing below error,
F:\ProjectPath>expo start
Starting project at F:\ProjectPath
Expo DevTools is running at http://localhost:19002
Error: Missing app.json. See https://docs.expo.io/
No Expo configuration found. Are you sure this is a project directory?