JimmyPun610 / BarcodeScanner.Mobile

Barcode Scanner using GoogleVision API for Xamarin Form, Maui
MIT License
333 stars 100 forks source link

Linking using 'SDK Assemblies Only' results in crash on android when a barcode is found #158

Closed Stef-Halmans closed 1 year ago

Stef-Halmans commented 1 year ago

Describe the bug We were having issues with ZXing.Mobile.Net.Forms so we decided to give this library a try. It works really well with linking set to None, but as soon as we use the option Sdk Assemblies Only for linking the app crashes with the stacktrace below. This sucks because our app gets really big without linking. This does not happen with just the camera open, it only happens when a barcode is in the camera view, suggesting it sees a barcode before this exception occurs. Does anyone know a solution to this or some information that might help us tackle this problem?


OnePlus NE2213  Error   23478   AndroidRuntime  java.lang.NoSuchFieldError: no "Z" field "isRecognized" in class "Lcom/google/android/libraries/barhopper/Barcode;" or its superclasses
    at com.google.android.libraries.barhopper.BarhopperV2.recognizeBufferNative(Native Method)
    at com.google.android.libraries.barhopper.BarhopperV2.recognize(com.google.mlkit:barcode-scanning@@16.1.2:6)
    at com.google.mlkit.vision.barcode.bundled.internal.zza.zzf(com.google.mlkit:barcode-scanning@@16.1.2:4)
    at com.google.mlkit.vision.barcode.bundled.internal.zza.zzb(com.google.mlkit:barcode-scanning@@16.1.2:3)
    at com.google.android.gms.internal.mlkit_vision_barcode_bundled.zzaa.zza(com.google.mlkit:barcode-scanning@@16.1.2:3)
    at com.google.android.gms.internal.mlkit_vision_barcode_bundled.zzb.onTransact(com.google.mlkit:barcode-scanning@@16.1.2:3)
    at android.os.Binder.transact(Binder.java:1084)
    at com.google.android.gms.internal.mlkit_vision_barcode.zza.zzb(com.google.android.gms:play-services-mlkit-barcode-scanning@@16.1.5:2)
    at com.google.android.gms.internal.mlkit_vision_barcode.zzmz.zzd(com.google.android.gms:play-services-mlkit-barcode-scanning@@16.1.5:4)
    at com.google.mlkit.vision.barcode.internal.zzm.zza(com.google.android.gms:play-services-mlkit-barcode-scanning@@16.1.5:11)
    at com.google.mlkit.vision.barcode.internal.zzi.zzc(com.google.android.gms:play-services-mlkit-barcode-scanning@@16.1.5:3)
    at com.google.mlkit.vision.barcode.internal.zzi.run(com.google.android.gms:play-services-mlkit-barcode-scanning@@16.1.5:1)
    at com.google.mlkit.vision.common.internal.MobileVisionBase.zza(com.google.mlkit:vision-common@@16.4.0:1)
    at com.google.mlkit.vision.common.internal.zzc.call(Unknown Source:4)
    at com.google.mlkit.common.sdkinternal.ModelResource.zza(com.google.mlkit:common@@17.3.0:8)
    at com.google.mlkit.common.sdkinternal.zzm.run(Unknown Source:10)
    at com.google.mlkit.common.sdkinternal.zzp.run(com.google.mlkit:common@@17.3.0:2)
    at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zze(com.google.mlkit:common@@17.3.0:4)
    at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzc(com.google.mlkit:common@@17.3.0:1)
    at com.google.mlkit.common.sdkinternal.zzi.run(Unknown Source:2)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
    at com.google.mlkit.common.sdkinternal.MlKitThreadPool.zzd(com.google.mlkit:common@@17.3.0:2)
    at com.google.mlkit.common.sdkinternal.zzj.run(Unknown Source:2)
    at java.lang.Thread.run(Thread.java:1012)

To Reproduce Steps to reproduce the behavior:

  1. Add BarcodeScanner.Mobile.XamarinForms to your project
  2. Configure it according to the wiki
  3. Set linking to Sdk Assemblies Only
  4. Build the project in debug or release mode to an android device
  5. See exception followed by crash

Expected behavior The barcode would be scanned without crashing

Smartphone (please complete the following information):

Additional context We already tried adding the following lines to our proguard.cfg file, although we dont have much experience with progurad. These lines didnt fix the problem: -keep class com.google.mlkit.* { ; } -keep interface com.google.mlkit.* { ; }

It does work on IOS using Link Framework SDKs Only.

Stef-Halmans commented 1 year ago

I fixed the issue, by adding 2 more lines in the proguard.cfg file, so I now have the following:


-keep class com.google.mlkit.**  { *; }
-keep interface com.google.mlkit.**  { *; }

-keep class com.google.android.libraries.barhopper.**  { *; }
-keep interface com.google.android.libraries.barhopper.**  { *; }
This works with linking set to 'Sdk Assemblies Only'. So the issue is resolved. I don't know if this is the only, or best solution, but it worked for me.
mos379 commented 1 year ago

@Stef-Halmans Thanks for this! This should be included in documentation!!!

LeoJHarris commented 10 months ago

Just stumbled on the same issue after a QA few iterations of our app, definitely should be documented! @JimmyPun610