EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 446 forks source link

Barcode scanner crashes on Android with live video activated #1630

Open cjohn001 opened 4 years ago

cjohn001 commented 4 years ago

Hello together, I am trying to use the Barcode scanner with live video capture. On IOS the barcode scanner is running as expected. On an android device (Android 8.0) and also on an emulator (Android 9.0) the scanner fails with the same error:

Stacktrace from device:

System.err: An uncaught Exception occurred on "main" thread.
System.err: Calling js method onPreviewFrame failed
System.err: TypeError: Cannot read property 'firebase' of undefined
System.err: 
System.err: StackTrace:
System.err: push.../node_modules/nativescript-plugin-firebase/mlkit/barcodescanning/index.js.MLKitBarcodeScanner.preProcessImage(file: node_modules/nativescript-plugin-firebase/mlkit/barcodescanning/index.android.js:97:0)
System.err:     at onPreviewFrame(file: node_modules/nativescript-plugin-firebase/mlkit/mlkit-cameraview.android.js:168:0)
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1286)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1173)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1160)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1138)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1134)
System.err:     at com.tns.gen.android.hardware.Camera_PreviewCallback.onPreviewFrame(Camera_PreviewCallback.java:20)
System.err:     at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1124)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:105)
System.err:     at android.os.Looper.loop(Looper.java:164)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6944)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Stacktrace from Emulator:

System.err: An uncaught Exception occurred on "main" thread.
System.err: Calling js method onPreviewFrame failed
System.err: TypeError: Cannot read property 'firebase' of undefined
System.err: 
System.err: StackTrace:
System.err: push.../node_modules/nativescript-plugin-firebase/mlkit/barcodescanning/index.js.MLKitBarcodeScanner.preProcessImage(file: node_modules/nativescript-plugin-firebase/mlkit/barcodescanning/index.android.js:97:0)
System.err:     at onPreviewFrame(file: node_modules/nativescript-plugin-firebase/mlkit/mlkit-cameraview.android.js:168:0)
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1286)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1173)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1160)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1138)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1134)
System.err:     at com.tns.gen.android.hardware.Camera_PreviewCallback.onPreviewFrame(Camera_PreviewCallback.java:20)
System.err:     at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1209)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
System.err:     at android.os.Looper.loop(Looper.java:193)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6669)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Has someone an idea what is going wrong here or how I can work arround the issue? Thanks for your help.

SudhakarPunniyakotti commented 4 years ago

Same error System.err: An uncaught Exception occurred on "main" thread. System.err: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Error calling module function System.err: TypeError: Cannot read property 'tasks' of undefined System.err: File: (file:///node_modules/nativescript-plugin-firebase/mlkit/barcodescanning/index.js:7:0) System.err:

My versions

"tns-android": { "version": "6.2.0" } and "nativescript-plugin-firebase": "^10.5.2",

Any help will be highly appreciated, thank you ...

cjohn001 commented 4 years ago

@sudhakar, Hello, it seems like the error is related to the android simulator which provides a kind of virtual camera in which you can setup a virtual scene to capture an image. The first time this simulation is loaded there seems to not exist an image preset. This seems to be responsible for the crash. Maybe use a different app to once start the simulation, The issue stopped appearing to me after this even if I am using new simulator images.

Best regards, Christoph

zalesak commented 3 years ago

As a quick workaround drop support for inverse code scanning. <MLKitBarcodeScanner ... supportInverseBarcodes="false" ...

zalesak commented 3 years ago

@EddyVerbruggen can you help here? It seems that call for java function doesn`t work..

zalesak commented 3 years ago

So gyus, i found it out.

Just rename

node_modules\@nativescript\firebase\platforms\android\nativescript-firebase-mlkit-helper.jar-disabled

to

node_modules\@nativescript\firebase\platforms\android\nativescript-firebase-mlkit-helper.jar

I`ll create PR to solve this.