Skip to content

🐛 [firebase_ml_vision][iOS] PlatformException(Error 13, com.firebase.ml, Barcode engine is nil., null) #4297

@llullanqui

Description

@llullanqui

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. 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();
  }
Podfile

# Uncomment this line to define a global platform for your project
platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

# post_install do |installer|
#   installer.pods_project.targets.each do |target|
#     flutter_additional_ios_build_settings(target)
#   end
# end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
    end
  end
end

# pod 'Firebase/MLVisionBarcodeModel'
pod 'GoogleMLKit/BarcodeScanning'

flutter build ios error when having pod 'Firebase/MLVisionBarcodeModel' in the Podfile (Was too long to post):
File

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs AttentionThis issue needs maintainer attention.type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions