ML Kit Vision on-device text recognition not downloading model: Waiting for the text recognition model to be downloaded. Please wait
Asked Answered
G

3

10

I know there are many similar questions (here, here or here) but even though I've followed the suggested instructions I'm still facing the same issue.

Even though it seems I have the project configured correctly, the Firebase ML Kit seems to have issues to download the on-device text recognition model giving me the following exception:

com.google.firebase.ml.common.FirebaseMLException: Waiting for the text recognition model to be downloaded. Please wait.

The project seems to be configured as required with the DEPENDENCIES metadata in the manifest to download the dependencies upon opening the app (or downloading from the Play Store):

<meta-data
   android:name="com.google.firebase.ml.vision.DEPENDENCIES"
   android:value="ocr" />

As well as permissions to access the Internet and Cameras:

 <uses-permission android:name="android.permission.CAMERA" />
 <uses-permission android:name="android.permission.INTERNET" />

The :app Gradle has the implementation of the ML Kit Vision:

implementation 'com.google.firebase:firebase-ml-vision:24.0.1'

I've also tried:

  1. Deleting all data of the Google Play Services: Settings->Apps->Google Play Services->Storage->Manage Space->Clear All Data.
  2. Update Google Play Services, reboot and have Google Play Store open for like 15mins. Version installed: 20.09.13 (120408-298964066).
  3. Low storage check (13GB Free).
  4. Remove/give permission of the camera to the app & Google Play Services.

The code where I try to use the library is here (an implementation of the interface ImageAnalysis.Analyzer):

@SuppressLint("UnsafeExperimentalUsageError")
    override fun analyze(imageProxy: ImageProxy) {
        Log.d(LOG_TAG, "Trying to detect something")
        val mediaImage = imageProxy.image
        val imageRotation = degreesToFirebaseRotation(imageProxy.imageInfo.rotationDegrees)
        if (mediaImage != null) {
            val firebaseImage = FirebaseVisionImage.fromMediaImage(mediaImage, imageRotation)
            val detector = FirebaseVision.getInstance().onDeviceTextRecognizer
            val result = detector.processImage(firebaseImage)
                .addOnSuccessListener { firebaseVisionText ->
                    // Task completed successfully
                    Log.d(LOG_TAG, "Text detected! ${firebaseVisionText.text}")

                    // Close img for next use
                    imageProxy.close()
                }
                .addOnFailureListener { e ->
                    // Task failed with an exception
                    Log.e(LOG_TAG, e.toString())
                    e.printStackTrace()

                    // Close img for next use
                    imageProxy.close()
                }
        }
    }

It has been written following the official instructions here.

This is the complete output:

W/izadi.explorat: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.dynamite.ocr not found.
I/DynamiteModule: Considering local module com.google.android.gms.vision.dynamite.ocr:0 and remote module com.google.android.gms.vision.dynamite.ocr:0
D/TextNativeHandle: Cannot load feature, fall back to load dynamite module.
W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.ocr not found.
I/DynamiteModule: Considering local module com.google.android.gms.vision.ocr:0 and remote module com.google.android.gms.vision.ocr:0
E/Vision: Error loading module com.google.android.gms.vision.ocr optional module true: com.google.android.gms.dynamite.DynamiteModule$LoadingException: No acceptable module found. Local version is 0 and remote version is 0.
E/OcrAnalyzer: com.google.firebase.ml.common.FirebaseMLException: Waiting for the text recognition model to be downloaded. Please wait.
W/System.err: com.google.firebase.ml.common.FirebaseMLException: Waiting for the text recognition model to be downloaded. Please wait.
W/System.err:     at com.google.android.gms.internal.firebase_ml.zzsc.zzd(com.google.firebase:firebase-ml-vision@@24.0.1:21)
        at com.google.android.gms.internal.firebase_ml.zzsc.zza(com.google.firebase:firebase-ml-vision@@24.0.1:39)
        at com.google.android.gms.internal.firebase_ml.zzpj.zza(com.google.firebase:firebase-ml-common@@22.0.1:31)
        at com.google.android.gms.internal.firebase_ml.zzpl.call(Unknown Source:8)
        at com.google.android.gms.internal.firebase_ml.zzpf.zza(com.google.firebase:firebase-ml-common@@22.0.1:32)
        at com.google.android.gms.internal.firebase_ml.zzpe.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at com.google.android.gms.internal.firebase_ml.zze.dispatchMessage(com.google.firebase:firebase-ml-common@@22.0.1:6)
        at android.os.Looper.loop(Looper.java:227)
        at android.os.HandlerThread.run(HandlerThread.java:67)



Any ideas?

Does someone have any idea on what I'm missing or how to solve it? It happens both in my device (Xiaomi Mi 8 - Android 10) and the virtual device (Nexus 5X - Android 10 + Play Store).

Genie answered 13/3, 2020 at 7:45 Comment(0)
G
5

In the end, after trying it in different devices I realised that the issue seemed to be related to how the Google Play Services were installed in the device.

In the original testing device, the Google Play Services were installed as user apps and this apparently prevented the optional module being downloaded. After installing the Play Services at the system level the issue was solved.

TLDR: for the optional modules to be downloaded, Google Play Services need to be installed at system level apparently.

Genie answered 7/5, 2020 at 8:49 Comment(2)
What does it mean "system level"?Autograft
@Autograft I meant that the Google Apps need to be installed at /system instead of just being user apps directly installed from the APKs. By being in /system they can access more privileged permissions that seem to be needed in this case. More info: android.stackexchange.com/questions/17871/…Genie
I
5

Thanks for your feedback!

The google play service version 20.09.13 that you have is not in our currently supported list for optional module download. Theoretically, we should support all versions that currently in prod after 19.8.31(this will change when new version comes out). I will double check with mu colleague to see why you got 20.08.13 and it is not in the serving list.

In the meantime, could you try to update it again to see if you can get a new version of google play service?

Thanks!

Ideational answered 18/4, 2020 at 2:21 Comment(5)
Your answer implies that you are affiliated with something (e.g. saying "in our currently supported list"), but you don't mention your affiliation here, your other answer, or in your profile. It would help for understanding this answer, and your other answer, if you were to mention that affiliation in your answers and/or in your profile. It's not required that you do so, given that you're not linking to or promoting something, but doing so would certainly make your answers more understandable. Also, the salutation "Thanks for your feedback" really isn't accurate/appropriate for Stack Overflow.Rola
My Google Play Services were updated automatically to 20.12.16 but I still get the same error :/Genie
Hi, the previous version you had 20.09.13 was re-spun to fix some bugs (the bugs are not related to optional modules). There was a bug in the optional module download path which requires a reboot if the Google Play Service version has been updated from an unsupported version to a new version for optional module download to work. Have you rebooted your device after Google Play Service version got updated? Could you try reboot your device to see if it helps? In the meantime, I will update here when the fix for a reboot requirement is release.Ideational
Hi, the fix I mentioned in the previous reply has already been pushed with 20.12.16. The optional module download for text usually takes a couple of minutes. If it still doesn't work for you, do you mind sharing a bugreport with us by sending it to [email protected] to help us further investigate the failure. Thanks!Ideational
Hi @ChenxiSong at the end I've been able to make the optional module work, I didn't have the Google Play Services as a system app and this apparently prevented the optional module being downloaded. After installing the Play Services at the system level the issue was solved. Thanks for the help anyhow!Genie
G
5

In the end, after trying it in different devices I realised that the issue seemed to be related to how the Google Play Services were installed in the device.

In the original testing device, the Google Play Services were installed as user apps and this apparently prevented the optional module being downloaded. After installing the Play Services at the system level the issue was solved.

TLDR: for the optional modules to be downloaded, Google Play Services need to be installed at system level apparently.

Genie answered 7/5, 2020 at 8:49 Comment(2)
What does it mean "system level"?Autograft
@Autograft I meant that the Google Apps need to be installed at /system instead of just being user apps directly installed from the APKs. By being in /system they can access more privileged permissions that seem to be needed in this case. More info: android.stackexchange.com/questions/17871/…Genie
M
0

try to add this dependencies :

// ML Kit dependencies
implementation 'com.google.firebase:firebase-ml-vision:24.0.1'
// Barcode detection model.
implementation 'com.google.firebase:firebase-ml-vision-barcode-model:16.0.2'
implementation 'com.google.firebase:firebase-ml-model-interpreter:22.0.1'

also check this link : Android Studio ML kit cannot load OCR module

Mai answered 13/3, 2020 at 7:50 Comment(2)
Thank you for the reply but it didn't work. It still gives me the same error :'(. Just to check I changed the onDeviceTextRecognizer to onDeviceImageLabeler and it works perfectly, so I don't really know what is going on with the Text Recogniser.Genie
firebase ml vision is deprecatedClarendon

© 2022 - 2025 — McMap. All rights reserved.