Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[camera] regression: startImageStream throws MissingPluginException on iOS #147702

Open
PerLycke opened this issue May 2, 2024 · 4 comments
Open
Assignees
Labels
c: crash Stack traces logged to the console c: regression It was better in the past than it is now found in release: 3.19 Found to occur in 3.19 found in release: 3.22 Found to occur in 3.22 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: camera The camera plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-ios iOS applications specifically team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team

Comments

@PerLycke
Copy link

PerLycke commented May 2, 2024

Steps to reproduce

  1. Create a new Flutter App
  2. Install camera package camera 0.10.5+9
  3. Add the following in your Info.plist:
	<key>NSCameraUsageDescription</key>
	<string>your usage description here</string>
	<key>NSMicrophoneUsageDescription</key>
	<string>your usage description here</string>
  1. Use the code below as your main.dart
  2. 'flutter run --release' using macos terminal with example code on an iPhone with iOS 17.4.1

Expected results

You should, on every run, see "STREAM" printed in console, and not get a MissingPluginException.

Actual results

Occasionally there is a MissingPluginException(No implementation found for method listen on channel plugins.flutter.io/camera_avfoundation/imageStream) thrown. We had this issue on earlier camera_avfoundation versions: #109910

It was fixed back then, but issue is back. The example code I provide is just a slightly modified version seen in the linked issue.

The issue doesn't happen all the time. However I did upload a build to TestFlight and the issue was persistent on that occasion. I, as much as you, hate bugs you cannot reproduce 100% of the time, but this is a serious issue and it can find its way into all apps using image stream on iOS, which I guess a lot of apps use these days.

This is the exact error I see, when it actually occurs, when running the example code:

flutter run --release
Running Xcode build...
└─Compiling, linking and signing... 1,312ms
Xcode build done. 21.5s
Installing and launching... 3.4s

Flutter run key commands.
h List all available interactive commands.
c Clear the screen
q Quit (terminate the application on the device).
[ERROR:flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.mm(42)] Using the Impeller rendering backend.
flutter: MissingPluginException(No implementation found for method listen on channel plugins.flutter.io/camera_avfoundation/imageStream)
flutter: #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332)
flutter:
flutter: #1 EventChannel.receiveBroadcastStream. (package:flutter/src/services/platform_channel.dart:676)
flutter:

Code sample

Code sample
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:wakelock_plus/wakelock_plus.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Cam issue',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  late CameraController controller;
  List<CameraDescription>? cameras;

  @override
  void initState() {
    loadCameras();
    super.initState();
  }

  loadCameras() async {
    try {
      cameras = await availableCameras();
      setState(() {});
    } on CameraException catch (e) {
      print('Error: ${e.code}\nError Message: ${e.description}');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Cam issue"),
      ),
      body: body(),
    );
  }

  body() {
    if (cameras?.isNotEmpty ?? false) {
      return Center(
        child: MyCameraPreview(cameras: cameras!),
      );
    }
    return const Center(
      child: Text("Loading"),
    );
  }
}

class MyCameraPreview extends StatefulWidget {
  final List<CameraDescription> cameras;

  const MyCameraPreview({
    Key? key,
    required this.cameras,
  }) : super(key: key);

  @override
  State<MyCameraPreview> createState() => _MyCameraPreviewState();
}

class _MyCameraPreviewState extends State<MyCameraPreview> {
  late CameraController controller;
  bool isDetecting = false;

  @override
  void initState() {
    initController();
    super.initState();
  }

  @override
  void dispose() {
    WakelockPlus.disable();
    super.dispose();
  }

  Future<void> initController() async {
    controller = CameraController(
      widget.cameras[0],
      ResolutionPreset.high,
      enableAudio: false,
    );
    await controller.initialize();
    final maxZoomValue = await controller.getMaxZoomLevel();
    await controller.lockCaptureOrientation();
    if (!mounted) {
      return;
    }

    await controller.startImageStream((CameraImage img) async {
      print("STREAM");
    });

    await WakelockPlus.enable();

    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return CameraPreview(controller);
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-arm64, locale en-GB)
    • Flutter version 3.19.6 on channel stable at /Users/per/dev/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 54e66469a9 (2 weeks ago), 2024-04-17 13:08:03 -0700
    • Engine revision c4cd48e186
    • Dart version 3.3.4
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/per/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

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

[✓] Connected device (3 available)
    • Per’s iPhone (mobile) • xxx-xxx • ios            • iOS 17.4.1 21E236
    • macOS (desktop)       • macos                     • darwin-arm64   • macOS 14.4.1 23E224 darwin-arm64
    • Chrome (web)          • chrome                    • web-javascript • Google Chrome 124.0.6367.118

[✓] Network resources
    • All expected network resources are available.

• No issues found!
@danagbemava-nc danagbemava-nc added the in triage Presently being triaged by the triage team label May 2, 2024
@huycozy
Copy link
Member

huycozy commented May 2, 2024

Thanks for the report. I checked this and saw different results below:

  • Flutter stable 3.19.6:
    • The issue is reproduced in debug mode.
    • I checked this a few times in release mode and couldn't reproduce the exception but I see callback wasn't being called
  • Flutter master 3.22.0-21.0.pre.20:
    • The issue is not reproduced in debug mode and the callback is called as expected.
    • In release mode, the result is the same on Flutter stable 3.19.6

But when I remove wakelock_plus usage from main.dart file, I don't see issue anymore on Flutter stable 3.19.6 in debug mode (in release mode, it stays the same as above). Could this package relate? Could you also check this again with these cases to make sure we see the same results?

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 2, 2024
@PerLycke
Copy link
Author

PerLycke commented May 2, 2024

Removing the use of wakelock_plus and I could no longer reproduce it on 3.19.6 stable. I'm not convinced about it though, as even with wakelock_plus it was not reproducible every time.

However, using something like wakelock_plus, with the intent of keeping your screen awake while using the camera and streaming images, causing the actual camera package to throw a MissingPluginException is weird, no?

Then I'm even more worried as one package can cause a package specific error to occur for a different package. I'm very confused.

That said, can we even conclude the use of wakelock_plus to be the actual issue here as it seems like some kind of race condition that happens occasionally?

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 2, 2024
@huycozy
Copy link
Member

huycozy commented May 3, 2024

I also see the same result at #109910 (comment) where the exception didn't occur but the camera stream callback wasn't called. Labeling this for further insights.

flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.19.6, on macOS 14.1 23B74 darwin-x64, locale en-VN)
    • Flutter version 3.19.6 on channel stable at /Users/huynq/Documents/GitHub/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 54e66469a9 (31 hours ago), 2024-04-17 13:08:03 -0700
    • Engine revision c4cd48e186
    • Dart version 3.3.4
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode15.3.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = /Applications/Android Studio.app/
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

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

[✓] Connected device (3 available)
    • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64  • Android 11 (API 30)
    • macOS (desktop)  • macos            • darwin-x64     • macOS 14.1 23B74 darwin-x64
    • Chrome (web)     • chrome           • web-javascript • Google Chrome 123.0.6312.124

[✓] Network resources
    • All expected network resources are available.

• No issues found!
[!] Flutter (Channel master, 3.22.0-23.0.pre.14, on macOS 14.1 23B74 darwin-x64, locale en-VN)
    • Flutter version 3.22.0-23.0.pre.14 on channel master at /Users/huynq/Documents/GitHub/flutter_master
    ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7c62afb444 (77 minutes ago), 2024-05-02 21:48:17 -0400
    • Engine revision c380e9fd41
    • Dart version 3.5.0 (build 3.5.0-127.0.dev)
    • DevTools version 2.35.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode15.3.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = /Applications/Android Studio.app/
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

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

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 14.1 23B74 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 124.0.6367.94

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

@huycozy huycozy added c: crash Stack traces logged to the console platform-ios iOS applications specifically p: camera The camera plugin package flutter/packages repository. See also p: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on fyi-ecosystem For the attention of Ecosystem team team-ios Owned by iOS platform team found in release: 3.19 Found to occur in 3.19 found in release: 3.22 Found to occur in 3.22 c: regression It was better in the past than it is now and removed in triage Presently being triaged by the triage team labels May 3, 2024
@js2702
Copy link

js2702 commented May 7, 2024

We are having the same issue. We've done some debugging and it looks to be a problem in the camera_avfoundation version 0.9.15+1. The 0.9.15 works. We also are using wakelock_plus, so we need to do more testing.

@stuartmorgan stuartmorgan added the triaged-ecosystem Triaged by Ecosystem team label May 8, 2024
@flutter-triage-bot flutter-triage-bot bot removed fyi-ecosystem For the attention of Ecosystem team triaged-ecosystem Triaged by Ecosystem team labels May 8, 2024
@MitchellGoodwin MitchellGoodwin added P2 Important issues not at the top of the work list triaged-ios Triaged by iOS platform team labels May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: crash Stack traces logged to the console c: regression It was better in the past than it is now found in release: 3.19 Found to occur in 3.19 found in release: 3.22 Found to occur in 3.22 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: camera The camera plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-ios iOS applications specifically team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team
Projects
None yet
Development

No branches or pull requests

7 participants