Android Gradle Plugin update 4.1.0 causing Barcode Scanner to Crash

Viewed 1131

MobileVisionBarcodeScannerhttps://github.com/KingsMentor/MobileVisionBarcodeScanner is being used to scan a QR code and has been working successfully without any problems until Android Gradle Plugin was updated to 4.1.0

It happens as follow

  1. The scanner activity is opened
  2. Press back to close
  3. Crash with the follow stacktrace

java.lang.RuntimeException: Unable to destroy activity {com.robusta.befit/com.robusta.befit.features.scanner.ScannerActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Thread$State java.lang.Thread.getState()' on a null object reference

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Thread$State java.lang.Thread.getState()' on a null object reference at com.google.android.gms.samples.vision.barcodereader.ui.camera.CameraSource$FrameProcessingRunnable.release(CameraSource.java:1117) at com.google.android.gms.samples.vision.barcodereader.ui.camera.CameraSource.release(CameraSource.java:327) at com.google.android.gms.samples.vision.barcodereader.ui.camera.CameraSourcePreview.release(CameraSourcePreview.java:84) at com.google.android.gms.samples.vision.barcodereader.BarcodeCapture.onDestroy(BarcodeCapture.java:308)

(CameraSource.java:1117

1 Answers

From gradle plugin 4.1 changelog:

Assertions in debug builds

When you build the debug version of your app using Android Gradle plugin 4.1.0 and higher, the built-in compiler (D8) will rewrite your app's code to enable assertions at compile time, so you always have assertion checks active.

Commenting the below code will make it work

assert (mProcessingThread.getState() == State.TERMINATED);

Please note: Moving to ML Kit is a permanent solution.

Related