mlkit
mlkit copied to clipboard
[Bug report] Title for the bug
Describe the bug Play service code scanner was broken this week. About week ago it's worked perfectly on my Samsung galaxy S20. Today I have next error:
InternalError: com.google.mlkit.common.MlKitException: Failed to scan code.
To Reproduce
GmsBarcodeScanning.getClient( requireContext(), GmsBarcodeScannerOptions.Builder() .setBarcodeFormats(Barcode.FORMAT_QR_CODE) .build() ).startScan().addOnSuccessListener { barcode ->}.addOnFailureListener { error-> Log.e("TEST", error.toString()) }
Expected behavior Open scanner.
SDK Info: com.google.android.gms:play-services-code-scanner:16.0.0-beta3
Smartphone:
- Samsung Galaxy S20(android 31)
- Sony xperia xz 1
Development Environment: (For Android issue feel free to skip this section)
- Android Studio Android Studio Electric Eel | 2022.1.1 Patch 1
The same problem here https://stackoverflow.com/questions/75661357/google-barcode-scanning-ml-kit-activity-crashes-on-certain-devices
Hi! Any solution?
Hi! Any solution?
Unfortunately I did not find solution
Had the same/a similar problem that was solved by clearing google play service cache and having it redownload the library next time it was used. Hope this helps.
Clearing the cache did not do it for me. I had to actually uninstall updates for the Google Play Service (was on version 23.x, base-version was 22.x) and then the barcode-scanner works (even if I re-install the update for Google Play Services again).
Clearing the cache did not do it for me. I had to actually uninstall updates for the Google Play Service (was on version 23.x, base-version was 22.x) and then the barcode-scanner works (even if I re-install the update for Google Play Services again).
Same situation. Barcode scanner works again removing version 23 of Google Play Services
I found this issue reported here: https://issuetracker.google.com/issues/261579118
I found that sending an urgent install request for the module seems to help:
implementation 'com.google.android.gms:play-services-code-scanner:16.0.0'
implementation 'com.google.android.gms:play-services-base:18.2.0'
val scanner = GmsBarcodeScanning.getClient(this)
val moduleInstallRequest =
ModuleInstallRequest.newBuilder()
.addApi(scanner) //Add the scanner client to the module install request
.build()
val moduleInstallClient = ModuleInstall.getClient(this)
//Send an urgent module install request see https://developers.google.com/android/guides/module-install-apis#send_an_urgent_module_install_request
//If you'd like the OS to determine the best time, use a deferred install request, but I'd recommend the urgent one
//See https://developers.google.com/android/guides/module-install-apis#send_a_deferred_install_request
moduleInstallClient
.installModules(moduleInstallRequest)
.addOnSuccessListener {
if (it.areModulesAlreadyInstalled()) {
Toast.makeText(this, "Modules are already installed", Toast.LENGTH_LONG).show()
}
Toast.makeText(this, "Modules successfully installed", Toast.LENGTH_LONG).show()
}
.addOnFailureListener {
Log.e("MainActivity", "Error installing modules", it)
}
@DevinDuricka It's real work! Thanks! But Google Code Scanner shows black screen when launching it today(
@DevinDuricka It's real work! Thanks! But Google Code Scanner shows black screen when launching it today(
Are you on a physical device or emulator? I've noticed the emulators will sometimes have a black screen, but from what I can tell, the physical devices work correctly. If you're on an emulator, try cold booting it. (If it's a physical device, then sorry, I don't know how to solve that one! 😔)
Yes, its hysical device. The scanner worked for several days, and now it has broken(
@DevinDuricka . It worked perfectly for now.Also removed metadata from AndroidManifest
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.
I came accross the same issue after updating my Samsung S21 To fix the issue : Go to App Info for Google Play Services Click on 'App Details in Store', uninstall then install
Thank you
On Wed, 25 Oct, 2023, 6:34 pm lalamifr, @.***> wrote:
I came accross the same issue after updating my Samsung S21 To fix the issue : Go to App Info for Google Play Services Click on 'App Details in Store', uninstall then install
— Reply to this email directly, view it on GitHub https://github.com/googlesamples/mlkit/issues/635#issuecomment-1779231825, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABS3FNGWYAUYWSND2QINJO3YBEE6NAVCNFSM6AAAAAAVU3NBRKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZZGIZTCOBSGU . You are receiving this because you commented.Message ID: @.***>
I found that sending an urgent install request for the module seems to help:
implementation 'com.google.android.gms:play-services-code-scanner:16.0.0' implementation 'com.google.android.gms:play-services-base:18.2.0'
val scanner = GmsBarcodeScanning.getClient(this) val moduleInstallRequest = ModuleInstallRequest.newBuilder() .addApi(scanner) //Add the scanner client to the module install request .build() val moduleInstallClient = ModuleInstall.getClient(this) //Send an urgent module install request see https://developers.google.com/android/guides/module-install-apis#send_an_urgent_module_install_request //If you'd like the OS to determine the best time, use a deferred install request, but I'd recommend the urgent one //See https://developers.google.com/android/guides/module-install-apis#send_a_deferred_install_request moduleInstallClient .installModules(moduleInstallRequest) .addOnSuccessListener { if (it.areModulesAlreadyInstalled()) { Toast.makeText(this, "Modules are already installed", Toast.LENGTH_LONG).show() } Toast.makeText(this, "Modules successfully installed", Toast.LENGTH_LONG).show() } .addOnFailureListener { Log.e("MainActivity", "Error installing modules", it) }
Thanks for the rescue codes