简体   繁体   中英

Google ML kit Barcode Scanner example app for android not able to detect barcodes

I'm trying to use the Google ML kit barcode detection feature. For this, I have installed this example app provided by google. I have also connected my app to one of my firebase projects. When I open the app and go to LivePreviewActivity in that Barcode detection. The camera starts but no barcode is detected!. As per the quick start guide I've also added

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

in my manifest file. Also I have included this

FirebaseVisionBarcodeDetectorOptions options =
            new FirebaseVisionBarcodeDetectorOptions.Builder()
                    .setBarcodeFormats(
                            FirebaseVisionBarcode.FORMAT_CODE_128)
                    .build(); 

in BarcodeScanningProcessor.java file.

The errors I'm getting is:

Barcode detection failed com.google.firebase.ml.common.FirebaseMLException: Waiting for the barcode detection model to be downloaded. Please wait.

E/BarcodeNativeHandle: Error Loading module

java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.chimera.DynamiteModuleInitializer"

I've installed this app on two phones Huawei Mate 8 and Samsung Galaxy S7 Edge. The app is not able to detect barcodes from both the phones.

My aim is to detect/scan barcodes from live camera preview. Thanks.

On the first part of the question "Waiting for the barcode detection model to be downloaded. Please wait." :

This can happen if there is not enough storage on the device or the data connection is not there on the device. Clear out the data of the Google Play Services and retrying should work:

Settings->Apps->Google Play Services->Storage->Manage Space->Clear All Data

On the meta-data tag in the manifest part of the question:

That helps with the production use case ie when the end-user installs the app from the Play Store, the models are downloaded at install time with that meta-data tag. However, during the development you still have to wait for the model to be downloaded once.

On the last part of the question about Dynamite module loading error (I don't have enough reputation to add a comment yet, so adding it here):

What Android version and the Google Play services version are you running?

Add this dependency. It worked for me.

implementation 'com.google.firebase:firebase-ml-vision-barcode-model:16.0.2'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM