UPDATE:
Maybe it works now since the March 21, 2023 update, maybe not. You can read more about it in the docs if you want to use it.
Note again that we haven't tested if it works now. We had to quickly decide on how to get barcode scanning working again. So we refactored our custom barcode scanning Capacitor plugin to use com.google.mlkit:barcode-scanning:17.1.0
instead. More info about it here. This requires a bit more effort, because you have to implement the UI yourself and the fancy scan animation is gone, but it just works and it seems to be faster.
We are using com.google.android.gms:play-services-code-scanner:16.0.0-beta3
in combination with a custom Capacitor plugin for scanning barcodes like EAN-13 and EAN-8, but on certain devices, the activity seems to crash whenever the user tries to open the Google's barcode scanner UI.
Here is the error log from logcat:
win=Window{f8c052d u0 com.[redacted]/com.google.mlkit.vision.codescanner.internal.GmsBarcodeScanningDelegateActivity} destroySurfaces: appStopped=true cleanupOnResume=false win.mWindowRemovalAllowed=false win.mRemoveOnExit=false win.mViewVisibility=4 caller=com.android.server.wm.ActivityRecord.destroySurfaces:6529 com.android.server.wm.ActivityRecord.destroySurfaces:6510 com.android.server.wm.ActivityRecord.notifyAppStopped:6574 com.android.server.wm.ActivityRecord.activityStopped:7162 com.android.server.wm.ActivityClientController.activityStopped:258 android.app.IActivityClientController$Stub.onTransact:613 com.android.server.wm.ActivityClientController.onTransact:136
The code that handles the scanning UI:
package com.[redacted];
import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;
import com.google.mlkit.vision.barcode.common.Barcode;
import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions;
import com.google.mlkit.vision.codescanner.GmsBarcodeScanning;
@CapacitorPlugin()
public class BarcodeScanner extends Plugin {
private void scan() {
GmsBarcodeScannerOptions options = new GmsBarcodeScannerOptions.Builder()
.setBarcodeFormats(Barcode.FORMAT_EAN_13, Barcode.FORMAT_EAN_8, Barcode.FORMAT_CODE_128, Barcode.FORMAT_ITF)
.allowManualInput()
.build();
GmsBarcodeScanning
.getClient(getContext(), options)
.startScan()
.addOnSuccessListener(this::onSuccess);
}
private void onSuccess(Barcode result) {
JSObject jsObject = new JSObject();
jsObject.put("content", result.getDisplayValue());
jsObject.put("format", result.getFormat());
this.getSavedCall().success(jsObject);
}
@PluginMethod
public void startScan(PluginCall call) {
this.saveCall(call);
this.scan();
}
}
The versions
minSdkVersion = 23
compileSdkVersion = 33
targetSdkVersion = 33
androidxActivityVersion = '1.6.1'
androidxAppCompatVersion = '1.6.1'
androidxCoordinatorLayoutVersion = '1.2.0'
androidxCoreVersion = '1.9.0'
androidxFragmentVersion = '1.5.5'
coreSplashScreenVersion = '1.0.0-rc01'
androidxWebkitVersion = '1.6.0'
junitVersion = '4.13.2'
androidxJunitVersion = '1.1.5'
androidxEspressoCoreVersion = '3.5.1'
cordovaAndroidVersion = '10.1.1'
We have updated the Android Webview to the latest version, as well as any implementation package inside the app and Capacitor plugin's build.gradle
files. We have no clue what causes the error, because the error description is very vague. We cannot find a solution anywhere. The error happens on a Galaxy Tab S7, where it has worked before. It suddenly stopped working, probably because of an internal update we don't know anything of. We have also tested with a Samsung Galaxy A51, but it just works on that device.