journeyapps / zxing-android-embedded

Barcode scanner library for Android, based on the ZXing decoder
https://journeyapps.com/
Apache License 2.0
5.68k stars 1.26k forks source link

v4.2.0 crashes on pre-lollipop android devices #645

Closed ShivamPokhriyal closed 2 years ago

ShivamPokhriyal commented 2 years ago

Description of the problem:

The readme has instructions for using the latest version on older API levels https://github.com/journeyapps/zxing-android-embedded#older-sdk-versions, but when used, the app crashes on devices running on API < 21.

The reason for the crash is the use of AudioAttributes introduced in this PR https://github.com/journeyapps/zxing-android-embedded/pull/587. AudioAttributes was added in API level 21.

Related Issue: https://github.com/journeyapps/zxing-android-embedded/issues/643

We should probably update the README and explicitly mention that the latest version isn't compatible with API < 21 devices.

Which library version are you using? E.g. 4.2.0.

Which phone/tablet are you using, and which Android version does it run? (e.g. Samsung Galaxy S5, Android 5.0) Android 4.4.2 and 4.4.4

In the case of an error do you have a stack trace or adb logs?

Fatal Exception: java.lang.NoClassDefFoundError: android.media.AudioAttributes$Builder
       at com.google.zxing.client.android.BeepManager.playBeepSound(BeepManager.java:97)
       at com.google.zxing.client.android.BeepManager.playBeepSoundAndVibrate(BeepManager.java:84)
       at com.journeyapps.barcodescanner.CaptureManager$1.barcodeResult(CaptureManager.java:80)
       at com.journeyapps.barcodescanner.DecoratedBarcodeView$WrappedCallback.barcodeResult(DecoratedBarcodeView.java:50)
       at com.journeyapps.barcodescanner.BarcodeView$1.handleMessage(BarcodeView.java:52)
       at android.os.Handler.dispatchMessage(Handler.java:98)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5584)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
       at dalvik.system.NativeStart.main(NativeStart.java)
ShivamPokhriyal commented 2 years ago

FYI @rkistner @ANewGalaxy

rkistner commented 2 years ago

Fixed in v4.3.0