There are many ways to do this, here's the way I do it:
-
Push it to GitHub.
-
Do
npm install --save git+https://github.com/deehidayat/react-native-ocr-reader.git
in your main project. -
Link the library:
-
Add the following to
android/settings.gradle
:include ':react-native-ocr-reader' project(':react-native-ocr-reader').projectDir = new File(settingsDir, '../node_modules/react-native-ocr-reader/android')
-
Add the following to
android/app/build.gradle
:... dependencies { ... compile project(':react-native-ocr-reader') }
-
Add the following to
android/app/src/main/java/**/MainApplication.java
:package com.motivation; import com.google.android.gms.samples.vision.ocrreader.OcrReaderPackage; // add this for react-native-ocr-reader public class MainApplication extends Application implements ReactApplication { @Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), new OcrReaderPackage() // add this for react-native-ocr-reader ); } }
-
-
Simply
import/require
it by the name defined in your library'spackage.json
:import OcrReader from 'react-native-ocr-reader' <OcrReader style={{flex: 1}} onTextRead={({data})=>{ console.log(data) }} />
-
You can test and develop your library by importing the
node_modules
library into Android Studio if you don't want to install it from git all the time.