Giter VIP home page Giter VIP logo

react-native-firebase-mlkit's Introduction

react-native-firebase-mlkit

React Native wrapper for functionality of https://developers.google.com/ml-kit/

Getting started

$ npm install react-native-firebase-mlkit --save

Compatibility

As of the moment, this wrapper of firebase Ml Kit supports Android and iOS.

Mostly automatic installation

$ react-native link react-native-firebase-mlkit

Don't forget to ...

  • add google-services.json to the appropriate folder (/android/app/) (Android only)
  • add GoogleService-Info.plist to the appropriate folder (/ios/) (iOS only)
  • install CocoaPods in your react-native project and add the following line to your Podfile then run pod install (iOS only)
     pod 'Firebase/Core'
     pod 'Firebase/MLVision'
     pod 'Firebase/MLVisionTextModel'
     pod 'Firebase/MLVisionBarcodeModel'
    

Manual installation

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-firebase-mlkit and add RNMlKit.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNMlKit.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<
Error: MLVisionTextModel duplicate symbols with React Native

    Solved enabling the dead code stripping in xcode for debug. 
    You can enable it in Target > Build Settings > search for "Dead code stripping". 

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.mlkit.RNMlKitPackage; to the imports at the top of the file
  • Add new RNMlKitPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:

    include ':react-native-firebase-mlkit'
    project(':react-native-firebase-mlkit').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-firebase-mlkit/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:

    ...
    dependencies {
        implementation 'com.google.firebase:firebase-core:16.0.1'
        implementation 'com.google.firebase:firebase-ml-vision:17.0.0'
    
        implementation (project(':react-native-firebase-mlkit')) {
            exclude group: 'com.google.firebase'
        }
    }
    
    // Place this line at the end of file
    
    apply plugin: 'com.google.gms.google-services'
    
    // Work around for onesignal-gradle-plugin compatibility
    com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
    
  3. Insert the following lines inside the dependencies block in android/build.gradle:

    buildscript {
        repositories {
            google()
            ...
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.0.1'
            classpath 'com.google.gms:google-services:4.0.2' // google-services plugin
        }
    }
    

Usage (Example using react-native-camera)

import RNMlKit from 'react-native-firebase-mlkit';

export class textRecognition extends Component {
  ...

  async takePicture() {
    if (this.camera) {
      const options = { quality: 0.5, base64: true, skipProcessing: true, forceUpOrientation: true };
      const data = await this.camera.takePictureAsync(options);
      // for on-device (Supports Android and iOS)
      const deviceTextRecognition = await RNMlKit.deviceTextRecognition(data.uri); 
      console.log('Text Recognition On-Device', deviceTextRecognition);
      // for cloud (At the moment supports only Android)
      const cloudTextRecognition = await RNMlKit.cloudTextRecognition(data.uri);
      console.log('Text Recognition Cloud', cloudTextRecognition);
    }
  };

  ...
}

react-native-firebase-mlkit's People

Contributors

brunoluigi avatar dested avatar hawry avatar lake-effect avatar mateuscardosogs avatar wahidnasri avatar wsliaw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-firebase-mlkit's Issues

Linking issues with manually (no Pods) iOS build

I followed the steps in https://github.com/mateusc42/react-native-firebase-mlkit#ios for an iOS manual installation, but when building either from the CLI or in XCode, I get the following error:

CompileC /Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/Objects-normal/x86_64/RNMlKit.o /Users/user/project/node_modules/react-native-firebase-mlkit/ios/RNMlKit.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (in target: RNMlKit)
    cd /Users/user/project/node_modules/react-native-firebase-mlkit/ios
    export LANG=en_US.US-ASCII
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-cache-path=/Users/user/project/ios/build/ModuleCache.noindex -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/user/project/ios/build/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wunreachable-code -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Wno-objc-interface-ivars -Werror=objc-root-class -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DDEBUG=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=0-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.1.sdk -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -mios-simulator-version-min=8.0 -g -Wno-sign-conversion -Winfinite-recursion -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-semicolon-before-method-body -fobjc-abi-version=2 -fobjc-legacy-dispatch -index-store-path /Users/user/project/ios/build/Index/DataStore -iquote /Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/RNMlKit-generated-files.hmap -I/Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/RNMlKit-own-target-headers.hmap -I/Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/RNMlKit-all-target-headers.hmap -iquote /Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/RNMlKit-project-headers.hmap -I/Users/user/project/ios/build/Build/Products/Debug-iphonesimulator/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/user/project/React -I../../react-native/React -I../../react-native/React/Base -I../../react-native/React/CxxBridge -I../../react-native/React/CxxModule -I../../react-native/React/CxxUtils -I../../react-native/React/DevSupport -I../../react-native/React/Fabric -I../../react-native/React/Inspector -I../../react-native/React/Modules -I../../react-native/React/Profiler -I../../react-native/React/UIUtils -I../../react-native/React/Views -I../../react-native/React/Base/Surface -I../../react-native/React/Fabric/Mounting -I../../react-native/React/Fabric/Surface -I../../react-native/React/Fabric/Utils -I../../react-native/React/Views/SafeAreaView -I../../react-native/React/Views/ScrollView -I../../react-native/React/Base/Surface/SurfaceHostingView -I../../react-native/React/Fabric/Mounting/ComponentViews -I../../react-native/React/Fabric/Mounting/MountItems -I../../react-native/React/Fabric/Mounting/ComponentViews/ActivityIndicator -I../../react-native/React/Fabric/Mounting/ComponentViews/Image -I../../react-native/React/Fabric/Mounting/ComponentViews/Root -I../../react-native/React/Fabric/Mounting/ComponentViews/ScrollView -I../../react-native/React/Fabric/Mounting/ComponentViews/Switch -I../../react-native/React/Fabric/Mounting/ComponentViews/Text -I../../react-native/React/Fabric/Mounting/ComponentViews/View -I/Users/user/project/ios/Frameworks -I/Users/user/project/ios/Pods/Firebase -I/Users/user/project/ios/Pods/Headers/Public -I/Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/DerivedSources/x86_64 -I/Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/DerivedSources -F/Users/user/project/ios/build/Build/Products/Debug-iphonesimulator -MMD -MT dependencies -MF /Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/Objects-normal/x86_64/RNMlKit.d --serialize-diagnostics /Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/Objects-normal/x86_64/RNMlKit.dia -c /Users/user/project/node_modules/react-native-firebase-mlkit/ios/RNMlKit.m -o /Users/user/project/ios/build/Build/Intermediates.noindex/RNMlKit.build/Debug-iphonesimulator/RNMlKit.build/Objects-normal/x86_64/RNMlKit.o

/Users/user/project/node_modules/react-native-firebase-mlkit/ios/RNMlKit.m:6:9: fatal error: 'FirebaseCore/FirebaseCore.h' file not found

#import <FirebaseCore/FirebaseCore.h>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

libRNFirebase.a is included in the build phases, and react-native itself builds and runs on its own. The error only comes up when I try to add this lib.

Is there a fix that doesn't require cocoapods?

Firebase CoreOnly compatibility

I am trying to install this library in a project that already has Firebase installed.
But when I run pod install, I got this error:

[!] CocoaPods could not find compatible versions for pod "Firebase/CoreOnly":
  In snapshot (Podfile.lock):
    Firebase/CoreOnly (= 8.11.0)

  In Podfile:
    Firebase/MLVisionTextModel was resolved to 5.0.0, which depends on
      Firebase/CoreOnly (= 5.0.0)

    RNFBApp (from `../node_modules/@react-native-firebase/app`) was resolved to 14.3.0, which depends on
      Firebase/CoreOnly (= 8.11.0)


You have either:
 * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
 * changed the constraints of dependency `Firebase/CoreOnly` inside your development pod `RNFBApp`.
   You should run `pod update Firebase/CoreOnly` to apply changes you've made.

I tried everything posted here, with no results:
https://stackoverflow.com/questions/56055142/cocoapods-could-not-find-compatible-versions-for-pod-firebase-coreonly

What should I do?

Install with expo ?

Hi,

I have following the automatic instruction but it's still doesn't work.
I have the following error with the example:

[Unhandled promise rejection: ReferenceError: Can't find variable: RNMlKit]

Manipulate the resultText

Hi, thank you for this text recognition library. I would like to know is there any example on how to manipulate the extracted text, and then fill it in a form? Thank you.

Barcodes?

Great initiative setting this up.

Does this code support the vision elements like Barcode? I looked into the code and I see only the text function. Can it be easily extended with the other functions like faces, barcodes etc?

https://firebase.google.com/docs/ml-kit/read-barcodes

If not, what would be the best way to bridge to a native code to call Firebase ML Kit?

Colliding with RNCamera on iOS, error: Undefined symbol: _OBJC_CLASS_$_BarcodeDetectorManagerMlkit

Thank you for building this mlkit bridge. I am having difficulty using this package with RNCamera.

I have RNFirebase and RNCamera both functioning correctly on my app, but when I link react-native-firebase-mlkit and install the necessary pods, I get the following build error (iOS):

Undefined symbols for architecture arm64: "_OBJC_CLASS_$_BarcodeDetectorManagerMlkit", referenced from: objc-class-ref in libRNCamera.a(RNCameraManager.o)

Has anyone else encountered difficulty using this library with RNCamera?

Xcode version: 10.2

From package.json:

"dependencies": {
    "@okgrow/react-native-copilot": "^2.4.1",
    "@react-native-firebase/mlkit": "^0.0.4",
    "eslint-config-rallycoding": "^3.2.0",
    "lodash": "^4.17.11",
    "moment": "^2.24.0",
    "react": "16.8.3",
    "react-native": "0.59.5",
    "react-native-appsee": "^2.6.1",
    "react-native-calendar-events": "^1.7.1",
    "react-native-calendars": "^1.32.0",
    "react-native-camera": "^2.6.0",
    "react-native-communications": "^2.2.1",
    "react-native-contacts": "^4.0.0",
    "react-native-datepicker": "^1.7.2",
    "react-native-elements": "^1.1.0",
    "react-native-firebase": "^5.3.1",
    "react-native-firebase-mlkit": "^0.6.2",
    "react-native-google-places-autocomplete": "^1.3.9",
    "react-native-immediate-phone-call": "^1.0.0",
    "react-native-keyboard-aware-scroll-view": "^0.8.0",
    "react-native-maps": "^0.24.2",
    "react-native-navigation-directions": "^1.0.3",
    "react-native-permissions": "^1.1.1",
    "react-native-router-flux": "^4.0.6",
    "react-native-sliding-panes": "^1.0.3",
    "react-native-snap-carousel": "^3.7.5",
    "react-native-svg": "^9.4.0",
    "react-native-swipeout": "^2.3.6",
    "react-native-unified-contacts": "^1.6.2",
    "react-native-vector-icons": "^6.4.2",
    "react-redux": "^7.0.2",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0",
    "s": "^0.1.1",
    "victory-native": "^32.0.2"

Build-Phases tab of Main project target
Screenshot 2019-05-18 13 46 31

On Device Recognition not accuracy on Android, iOS work perfect

I'm developing an on-device recognition app that works offline both Android an iOS.

I've tested on Android (Galaxy Note 9, Nokia 8.1, Galaxy S9, Galaxy Note 5): all of the phones seem hard to recognize text, 10 times tried, 1 time detected. It's really hard to work on Android

For iPhone (iPhone 5s, iPhone 6s, iPhone X): all of the phones detect like 99%. I've tried 10 times and all 10 times it shows correct 100%.

I use the code on Example.

Is there any step I need to do on Android? Sine on this document https://firebase.google.com/docs/ml-kit/android/recognize-text (Before you begin, number 3) it's said that the model will automatically download on the first time we use on-device text recognition

Thank you.

IOS-Crash: After Using function

I got a Problem on my iPhone X - Simulator.
I implemented all the things and my project also knows the import of react-native-firebase-mlkit.
But after I want to use the function, the app crashes and I dont get the Error. I use the same function like in the example. The difference is that im using react-native-image-picker to get the uri of my image.

"dependencies": {
"react": "16.6.3",
"react-native": "0.58.6",
"react-native-firebase-mlkit": "^0.6.2",
"react-native-image-picker": "^0.28.0"
},

Weird detection responses

Hey, thank you for creating this library, I think it'll be at the core of the next app I'm building..

I tried to make this work alongside React-native-camera, the process was pretty straightforward but I ran into errors while logging out the output of the detection.

For any image, the On Device Response is either gibberish or empty. And the cloud response fails with a promise rejection.

Here's what it looks like:
image

Would appreciate some help with this. Thanks again!

Not working on iPhone ()

Hi,
Thanks for this great repository.
I tried to implement this but failed.
What I did was like this:

  1. react-native init testApp
  2. cd testApp
  3. npm install react-native-firebase-mlkit --save
  4. react-native link react-native-firebase-mlkit
  5. Added GoogleService-Info.plist into /ios/
  6. pod init
  7. added
    pod 'Firebase/Core'
    pod 'Firebase/MLVision'
    pod 'Firebase/MLVisionTextModel'
    into Podfile
  8. pod install
  9. open xcworkspace file with xcode (tried both 10 and 9)
  10. build

Then I got this error:

screen shot 2018-08-31 at 3 33 38 pm

Do you know what I have done wrong?

Thanks!

Face detection Example

I am using React-native-firebase but it is currently missing Firebase ML Kit module.

Few questions:
-Would I be able to use this alongside React-Native-Firebase without issues?
-I wanted to use MLKit for on-device face detection to Blur faces in photos. Can you share example code for face detecting using this lib.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.