googlesamples / mlkit

A collection of sample apps to demonstrate how to use Google's ML Kit APIs on Android and iOS
Apache License 2.0
3.6k stars 2.94k forks source link

[Bug report] On emulator, Document Scanner throws "PlatformException(DocumentScanner, Failed to start document scanner, null, null)" #879

Closed pamtbaau closed 1 month ago

pamtbaau commented 1 month ago

Describe the bug When calling final documentScanner = DocumentScanner(options: options); an Exception is being thrown:

PlatformException(DocumentScanner, Failed to start document scanner, null, null)

To Reproduce Example Steps to reproduce the behavior in sample app:

  1. Create new flutter app using flutter create test --platform=android
  2. Replace content of main.dart with:

    import 'package:flutter/material.dart';
    import 'package:google_mlkit_document_scanner/google_mlkit_document_scanner.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          home: Scaffold(
            body: Center(
              child: IconButton(
                onPressed: _onCameraPressed,
                icon: const Icon(Icons.camera_alt),
              ),
            ),
          ),
        );
      }
    
      Future<void> _onCameraPressed() async {
        final options = DocumentScannerOptions();
    
        try {
          final documentScanner = DocumentScanner(options: options);
          final documents = await documentScanner.scanDocument();
        } catch (ex) {
          print(ex);
        }
      }
    }
  3. Run app on emulator using Android 14
  4. See printed error
    PlatformException(DocumentScanner, Failed to start document scanner, null, null)
  5. Run app on mobile device using Android 14 and all goes well.

Expected behavior As on my mobile phone camera should appear and document can be scanned.

SDK Info:

Smartphone:

pamtbaau commented 1 month ago

Moved issue to https://github.com/flutter-ml/google_ml_kit_flutter/issues/699