FlutterFire Firebase_ml_vision: PlatformException(Error 13, com.firebase.ml, Barcode engine is nil., null)

430 views Asked by At

I've been using the 'firebase_ml_vision' package to scan Qr codes in an Image Stream provided by the 'camera' package. Everything was fine until the update that happened in Nov. 6. In Android, I can still scan qr codes without problems. But in iOS, i'm having the app is throwing the Exception: PlatformException(Error 13, com.firebase.ml, Barcode engine is nil., null)

I've updated my podfile with the line pod 'GoogleMLKit/BarcodeScanning', because the command 'flutter build ios' finished with an error when the Podfile had pod 'Firebase/MLVisionBarcodeModel' instead. I did because the pod update command explained that the package 'Firebase/MLVisionBarcodeModel' was deprecated, and thought it was the source of the problem.

Still the problem keeps happening.

Flutter doctor -v output:

[✓] Flutter (Channel stable, 1.22.4, on Mac OS X 10.15.6 19G73 darwin-x64, locale en-EC)
    • Flutter version 1.22.4 at /Applications/flutter_sdk/jaime/flutter
    • Framework revision 1aafb3a8b9 (3 weeks ago), 2020-11-13 09:59:28 -0800
    • Engine revision 2c956a31c0
    • Dart version 2.10.4

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/jvasquez/Library/Android/sdk
    • Platform android-29, build-tools 29.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.1, Build version 12A7403
    • CocoaPods version 1.10.0

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 46.0.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.51.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.16.0

[!] Connected device
    ! No devices available

! Doctor found issues in 1 category.

This is the code I use to analyze the CameraImage:

  static Future<List<Barcode>> detect({
    @required CameraImage image,
    // @required BarcodeDetector detector,
    @required int imageRotation,
  }) async {
    var rp = List<Barcode>();
    try {
      BarcodeDetector detector = FirebaseVision.instance.barcodeDetector(
        BarcodeDetectorOptions(
          barcodeFormats: BarcodeFormat.qrCode,
        )
      );
      var metadata = _buildMetaData(image, _rotationIntToImageRotation(imageRotation));
      FirebaseVisionImage visionImage = FirebaseVisionImage.fromBytes(_concatenatePlanes(image.planes), metadata);
      rp = await detector.detectInImage(visionImage);
    } catch (ex) {
      print("Ocurrió un error: $ex");
      // UtilFunctions.escribirEnLog(
      //   mensaje: "$ex",
      //   nombreFuncion: "detect",
      //   tipo: 0,
      // );
    }
    
    return rp;
  }

  static Uint8List _concatenatePlanes(List<Plane> planes) {
    final WriteBuffer allBytes = WriteBuffer();
    for (Plane plane in planes) {
      allBytes.putUint8List(plane.bytes);
    }
    return allBytes.done().buffer.asUint8List();
  }
1

There are 1 answers

0
Florian Vögtle On

The problem is, that firebase_ml_vision internally uses Firebase/MLVisionBarcodeModel and not GoogleMLKit/BarcodeScanning.

In the issue https://github.com/FirebaseExtended/flutterfire/issues/4625 another user forked the firebase_ml_vision package and adjusted it to work with GoogleMLKit/BarcodeScanning. There is also a PR for this form (https://github.com/FirebaseExtended/flutterfire/pull/5378). It is important to mention that some functionality, especially cloud functionality, has been removed to make it work. Therefore, this could break parts of your app where these features are missing and it is yet not a great solution.

To use the forked package include the following in your Pubspec.yaml

firebase_ml_vision:
git:
  url: git://github.com/algirdasmac/flutterfire
  path: packages/firebase_ml_vision