Skip to content

Integrating the [camera](https://pub.dev/packages/camera) plugin with version 0.11.2 keeps logging ImageReader_JNI warning: W/ImageReader_JNI(10607): Unable to acquire a buffer item, very likely client tried to acquire more than maxImages buffers #179129

@laurens-pilot

Description

@laurens-pilot

Steps to reproduce

  1. Add camera plugin with version 0.11.2
  2. Open the in-app camera on Android
  3. Push another screen on top of this camera page

Expected results

No warning logs.

Actual results

Infinite warning logs of the following line:
W/ImageReader_JNI(10607): Unable to acquire a buffer item, very likely client tried to acquire more than maxImages buffers

Code sample

Code sample
import "dart:async";

import "package:camera/camera.dart";
import "package:flutter/material.dart";

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  final cameras = await availableCameras();
  runApp(MyApp(cameras: cameras));
}

class MyApp extends StatelessWidget {
  const MyApp({required this.cameras, super.key});

  final List<CameraDescription> cameras;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "ImageReader_JNI repro",
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.green),
        useMaterial3: true,
      ),
      home: HomePage(cameras: cameras),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({required this.cameras, super.key});

  final List<CameraDescription> cameras;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Home")),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            Navigator.of(context).push(
              MaterialPageRoute(
                builder: (_) => CameraPreviewPage(cameras: cameras),
              ),
            );
          },
          child: const Text("Open camera page"),
        ),
      ),
    );
  }
}

class CameraPreviewPage extends StatefulWidget {
  const CameraPreviewPage({required this.cameras, super.key});

  final List<CameraDescription> cameras;

  @override
  State<CameraPreviewPage> createState() => _CameraPreviewPageState();
}

class _CameraPreviewPageState extends State<CameraPreviewPage> {
  CameraController? _controller;
  bool _initializing = true;
  String? _error;

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

  Future<void> _startCamera() async {
    if (widget.cameras.isEmpty) {
      setState(() {
        _error = "No cameras found on this device.";
        _initializing = false;
      });
      return;
    }
    try {
      final controller = CameraController(
        widget.cameras.first,
        ResolutionPreset.medium,
        enableAudio: false,
      );
      await controller.initialize();
      if (!mounted) {
        await controller.dispose();
        return;
      }
      setState(() {
        _controller = controller;
        _initializing = false;
      });
    } catch (e) {
      setState(() {
        _error = "Failed to start camera: $e";
        _initializing = false;
      });
    }
  }

  @override
  void dispose() {
    _controller?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Camera preview")),
      body: Column(
        children: [
          Padding(
            padding: const EdgeInsets.all(12),
            child: Text(
              "Steps to repro:\n1. Open this camera page.\n2. Tap \"Push next screen\" below without closing the preview.\n3. Watch logcat for repeated \"ImageReader_JNI: Unable to acquire a buffer item\" warnings while the next screen is visible.",
            ),
          ),
          Expanded(child: Center(child: _buildPreview())),
          Padding(
            padding: const EdgeInsets.all(12),
            child: ElevatedButton(
              onPressed: () {
                Navigator.of(
                  context,
                ).push(MaterialPageRoute(builder: (_) => const SecondPage()));
              },
              child: const Text("Push next screen (preview keeps running)"),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildPreview() {
    if (_error != null) {
      return Text(_error!);
    }
    if (_initializing) {
      return const CircularProgressIndicator();
    }
    final controller = _controller;
    if (controller == null || !controller.value.isInitialized) {
      return const Text("Controller not initialized");
    }
    return AspectRatio(
      aspectRatio: controller.value.aspectRatio,
      child: CameraPreview(controller),
    );
  }
}

class SecondPage extends StatelessWidget {
  const SecondPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Second page")),
      body: const Center(
        child: Text(
          "This page sits on top of the running camera preview.\n"
          "On some Android devices, logcat starts spamming the ImageReader_JNI warning while this page is visible.",
          textAlign: TextAlign.center,
        ),
      ),
    );
  }
}

Screenshots or Video

Logs

Logs
W/ImageReader_JNI(10607): Unable to acquire a buffer item, very likely client tried to acquire more than maxImages buffers

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel [user-branch], 3.32.8, on macOS 26.1 25B78 darwin-arm64, locale
    en-US)
    ! Flutter version 3.32.8 on channel [user-branch] at /opt/homebrew/share/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official
      channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at
      https://flutter.dev/setup.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this
      error.
[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
[✓] Xcode - develop for iOS and macOS (Xcode 26.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2025.1)
[✓] VS Code (version 1.106.1)
[✓] Connected device (4 available)
[✓] Network resources

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in triagePresently being triaged by the triage teamwaiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions