Android Question External Library error after upgrade to AndroidX

sgt

Member
Licensed User
Longtime User
Hi just wanting to see if anyone can point me in the right direction to resolve the following issue.

I have a external library that I have written a simple wrapper for Google MLKit for text recognition. It was working before installing Android sdk 28 so I suspect its a dependency issue that i am missing with updated firebase vision components. The old one was using version 18.0.0 of the library where it now is using version 22.0.0 The error occurs in the library on

B4X:
FirebaseVisionTextRecognizer detector = FirebaseVision.getInstance().getOnDeviceTextRecognizer();

and the error is (Which is similar to thread https://www.b4x.com/android/forum/threads/firebase-ml-vision-lib-running-crash.107972/#post-678002)

Any help appreciated, Thanks.

B4X:
Error occurred on line: 198 (Camera)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object com.google.firebase.ml.common.internal.zzd.get(java.lang.Object)' on a null object reference
    at com.google.firebase.ml.common.internal.zzm.zza(com.google.firebase:firebase-ml-common@@20.0.1:24)
    at com.google.android.gms.internal.firebase_ml.zzrj.<init>(com.google.firebase:firebase-ml-vision@@22.0.0:5)
    at com.google.android.gms.internal.firebase_ml.zzrg.<init>(com.google.firebase:firebase-ml-vision@@22.0.0:10)
    at com.google.android.gms.internal.firebase_ml.zzrg.zze(com.google.firebase:firebase-ml-vision@@22.0.0:7)
    at com.google.firebase.ml.vision.text.FirebaseVisionTextRecognizer.zza(com.google.firebase:firebase-ml-vision@@22.0.0:9)
    at com.google.firebase.ml.vision.FirebaseVision.getOnDeviceTextRecognizer(com.google.firebase:firebase-ml-vision@@22.0.0:17)
    at tytech.mlkit.ocr.TextRecongition.recognizeText(TextRecongition.java:63)
    at tytech.mlkit.ocr.TextRecongition.ocrImage(TextRecongition.java:51)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1083)
    at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:1038)
    at tytech.financenow.cameraexclass._camera_picturetaken(cameraexclass.java:400)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA$1.run(BA.java:335)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7037)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
 

DonManfred

Expert
Licensed User
Longtime User
Which is similar to thread
if you find a solution: please post it. I am facing the same problem with my wrapper.
 
Upvote 0

sgt

Member
Licensed User
Longtime User
Hello @DonManfred, have you had any luck with the same issue. I see the SDK had an update to ml-vision libraries to version 23.0.0 and now the error happens because the FirebaseVision.getInstance() method returns null now. With the following code I can create a FirebaseVisionImage object but when you go to create a FirebaseVision object to create anyone of the recongnizers it now fails with a null object error.

B4X:
    #AdditionalJar: com.google.firebase:firebase-ml-vision
#AdditionalJar: com.google.firebase:firebase-ml-common

Dim firebaseImage As JavaObject = GetFirebaseVisionImage(bmp)

'this returns null
Dim firebaseVision As JavaObject = GetFirebaseVision

' this will cause an null object error
Dim detector As JavaObject = GetFirebaseVisionTextRecognizer

Sub GetFirebaseVisionImage(bmp As Bitmap) As JavaObject
    Dim jo As JavaObject
    Return jo.InitializeStatic("com.google.firebase.ml.vision.common.FirebaseVisionImage").RunMethodJO("fromBitmap", Array(bmp))
End Sub

Sub GetFirebaseVision As JavaObject
    Dim jo As JavaObject
    Return jo.InitializeStatic("com.google.firebase.ml.vision.FirebaseVision").RunMethodJO("getInstance", Null)
End Sub

Sub GetFirebaseVisionTextRecognizer As JavaObject
    Dim jo As JavaObject
    Return jo.InitializeStatic("com.google.firebase.ml.vision.FirebaseVision").RunMethodJO("getInstance", Null).RunMethodJO("getOnDeviceTextRecognizer", Null)
End Sub

@Erel do you have any idea why this would be happening. Google has updated their example to use AndroidX and version 23 of these ml-vision libraries but the code has not really changed from the earlier versions where it was working. See https://github.com/firebase/snippet...le/mlkit/TextRecognitionActivity.java#L36-L37
 
Upvote 0
Top