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.45k stars 2.9k forks source link

[Bug report] BarcodeScanning getClient - MlKitContext has not been initialized #644

Open khosbayar-b opened 1 year ago

khosbayar-b commented 1 year ago

Describe the bug A clear and concise description of what the bug is. We started seeing this rarely on some devices at the moment. It is weird that getting MlKitContext has not been initialized even though we are not manually initializing a context (neither disabled content-provider as well)

If applicable, please include code snippet and sample input(image, video, text, etc)

java.lang.IllegalStateException: MlKitContext has not been initialized
    at com.google.android.gms.common.internal.Preconditions.checkState(com.google.android.gms:play-services-basement@@18.1.0:0)
    at com.google.mlkit.common.sdkinternal.MlKitContext.getInstance(com.google.mlkit:common@@18.5.0:13)
    at com.google.mlkit.vision.barcode.BarcodeScanning.getClient(com.google.android.gms:play-services-mlkit-barcode-scanning@@16.2.1:3)

Expected behavior A clear and concise description of what you expected to happen.

SDK Info:

Smartphone:

sebastian-zero commented 8 months ago

We see this too, though rarely, on Poco F5 devices running Android 13 with com.google.mlkit:barcode-scanning:17.2.0

superoidlau commented 6 months ago

I had the same problem on OPPO , Android 13.

Caused by:
5
java.lang.IllegalStateException:MlKitContext has not been initialized
6
com.google.android.gms.common.internal.Preconditions.checkState(com.google.android.gms:play-services-basement@@18.1.0:2)
7
com.google.mlkit.common.sdkinternal.MlKitContext.getInstance(com.google.mlkit:common@@18.7.0:1)

I am using these libraries:

implementation 'com.google.mlkit:barcode-scanning:17.1.0'
implementation 'com.google.mlkit:text-recognition:16.0.0-beta6'
implementation 'com.google.mlkit:text-recognition-chinese:16.0.0-beta6'
billzbh commented 2 months ago

I just code in application.java MlKitContext.initializeIfNeeded(this);