googlesamples / mlkit

A collection of sample apps to demonstrate how to use Google's ML Kit APIs on Android and iOS
Apache License 2.0
3.6k stars 2.94k forks source link

[Bug report] Running the mlkit_code_scanner_sample is not downloading Barcode UI #641

Open kometen opened 1 year ago

kometen commented 1 year ago

I am running the codescanner-project mlkit/android/codescanner on a Samsung Galaxy A40 running Android 11 with latest updates installed. The device is only for testing, connected to wifi, no login to any service nor any sim-card. There is 46 GB available diskspace.

The app is installed via android studio Electric Eel and usb.

  1. Install codescanner-demo from android studio on device.
  2. Select either Java or Kotlin
  3. Press SCAN BARCODE button
  4. Message is "Failed to scan code: com.google.mlkit.MlKitException: Waiting for the Barcode UI module to be downloaded"
  5. Press button after five minutes, same message

I have added the following to settings.gradle.

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
    }
}

build.gradle (project):

buildscript {
    ext.kotlin_version = '1.4.31'

    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

build.gradle (code-scanner-sample)

dependencies {
    implementation 'com.google.android.gms:play-services-code-scanner:16.0.0-beta3'
}

AndroidManifest.xml:

    <meta-data
        android:name="com.google.mlkit.vision.DEPENDENCIES"
        android:value="barcode_ui"/>
kometen commented 1 year ago

Downgrading to beta1 works!?!?

dependencies {
    implementation 'com.google.android.gms:play-services-code-scanner:16.0.0-beta1'
}

But after the app runs and I can scan a QR-code, then clear the Google Play searvices cache and restart the app I am getting the same error. So it does not seem it's the app but rather a constraint on the delivery-side (Google) that causes the issue.

How can I bundle the Barcode UI with the app rather than the unreliable delivery-side?

kometen commented 1 year ago

So:

  1. When I erase the phone, re-install the app, the barcode-scanner works. After a delay downloading the Barcode UI.
  2. When I clear the Google Play services cache the barcode-scanner works.
  3. When I go into Manage storage and CLEAR ALL DATA it does not download the Barcode UI module.
bo-rik commented 1 year ago

I have the same issue. I configured the mete-data tag in the AndroidManifest.xml, but the dependency is not automatically downloaded. Only when the user wants to use the Scanner for the first time, the download of the required models is triggered. A couple of seconds later, on a second try, the Scanner (most of the time) works. So it seems the pre-download (when the app is downloaded from the Play Store) does not work.

chandragithub2014 commented 1 year ago

Is there a way can this issue be resolved. I am using the below dependency : implementation 'com.google.android.gms:play-services-code-scanner:16.0.0'

chandragithub2014 commented 1 year ago

OmniDirectional barcode is not scanned by Google code scanner. I tried to scan barcode from below url, no scan results were produced after scan: https://www.gs1.org/standards/barcodes/databar Please help me regarding this issue

pwojtowicz-rg commented 1 year ago

Same for Android 11 (Samsung Galaxy A50) and Android 13 (Samsung Galaxy A14 5G).

Ist there a chance anybody will look at it? Or should I use plain good old methods?

kvertner commented 1 year ago

Running into the same issue on a Galaxy S20 (Android 13).
I'm using implementation 'com.google.android.gms:play-services-code-scanner:16.0.0'

It was working last week, then over the weekend device did a system update (coincidence?) Anyway, I cleared PlayStore cache, rebooted, made sure I have the latest version of PlayStore. No luck! I also downgraded to the beta release with no luck.

Looking more and more like I'll have to go back to the old way of doing it. :(

nolimitdev commented 1 year ago

I had the problem MlKitException: Failed to scan code. It seems to be some google bug which sometimes happen. In my case google code scanner was working one day but on the next day does not without any code change. I just deleted data of Google Play services app. After that I got error CODE_SCANNER_UNAVAILABLE (Required code scanner module is not available yet) see https://developers.google.com/android/reference/com/google/mlkit/common/MlKitException and this means that just wait a few seconds and try again and google code scanner will work - this is just in local development when app is not installed via play store. In usual case google installs code scanner with app if you have <meta-data android:name="com.google.mlkit.vision.DEPENDENCIES" android:value="barcode_ui" /> in AndroidManifest.xml.

Great to debug is android app in play store https://play.google.com/store/apps/details?id=com.khandev.qrcodescanner which uses google code scanner library. You can test that when you delete play services data and install that app from play store and open it after several second later google code scanner is working so lib was pre-installed with app before first app use.

So implement manual downloading by this doc https://developers.google.com/android/guides/module-install-apis is useless. In local dev after first use you will got CODE_SCANNER_UNAVAILABLE and later it will work whe google downloads it.

rvanderlinden commented 1 year ago

This problem also occurs if you attempt to use your own implementation of the Google Play Services code scanner com.google.android.gms:play-services-code-scanner:16.1.0.

Conceptually, you need to check the availability of the scanner, install the module if it is not available, and then you can supposedly use the scanner in the OnSuccessListener. Unfortunately directly after that success callback (meaning the module has been installed) or even with a slight delay, you will still get the error com.google.mlkit.common.MlKitException: Waiting for the Barcode UI module to be downloaded. when starting the scanner. This should clear up 'in a bit' when that module has been installed in the background.

It would be incredibly helpful if we could also install the Barcode UI module using the ModuleInstallClient, but I haven't found a way to do so yet.

nolimitdev commented 1 year ago

@rvanderlinden I do not think we must install something. It is enough Google to fix bug when we use <meta-data android:name="com.google.mlkit.vision.DEPENDENCIES" android:value="barcode_ui" /> by doc it must be installed automatically within app installation. This lib was designed to be easy to use but Google MUST fix bugs and reliability. We do not need to take care manually about lib checking, installation, download progress etc.... too complicated.

hackaprende commented 7 months ago

Same issue here, no matter how much I wait I keep getting

com.google.mlkit.common.MlKitException: Waiting for the Barcode UI module to be downloaded.

Also added the

on the manifest and nothing.

AlanMaxwell commented 5 months ago

In my case it started to work when I turned on the internet connection on my device