camera1-to-camerax

Migrate Android Camera1 and Camera2 apps to CameraX with lifecycle-safe preview and capture.

174|8|Updated Jan 9, 2024
One-click install
npx skills add https://github.com/klxiaoniu/QQVersionList --skill camera1-to-camerax-klxiaoniu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: camera1-to-camerax
Source: https://github.com/klxiaoniu/QQVersionList/tree/main/.agents/skills/camera1-to-camerax
Command: npx skills add https://github.com/klxiaoniu/QQVersionList --skill camera1-to-camerax-klxiaoniu

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It solves the brittleness of legacy Android camera implementations by guiding you to replace Camera1 and raw Camera2 code with CameraX, reducing rotation bugs and handling device differences more reliably.

Core Features & Use Cases

  • Dependency setup for CameraX (including interoperability guidance): Ensures you add the correct CameraX artifacts for both Preview/ImageCapture and optional Compose integration.
  • Modern lifecycle-safe initialization: Replaces manual camera open/close logic with ProcessCameraProvider.bindToLifecycle tied to a LifecycleOwner.
  • Preview + tap-to-focus migration: Shows how to implement a correct preview pipeline and trigger focus/metering using CameraX APIs for both Views and Jetpack Compose.
  • Correct capture handling: Uses ImageCapture so rotation is handled via ImageProxy and emphasizes closing the proxy to avoid capture deadlocks.

Quick Start

Ask an AI to migrate your existing Android Camera1/Camera2 implementation to CameraX by adding the recommended dependencies, binding use cases to a lifecycle owner, wiring Preview and ImageCapture, and implementing tap-to-focus for either Views or Jetpack Compose.

Frequently Asked Questions about camera1-to-camerax

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate legacy Android camera code to CameraX?

Migrate legacy Android camera code to CameraX by adding CameraX dependencies, removing manual lifecycle and orientation matrix logic, and binding Preview and ImageCapture use cases via ProcessCameraProvider to achieve reliable preview and capture.

Can I use CameraX with Jetpack Compose for camera preview?

Yes, you can use CameraX with Jetpack Compose by adding the correct CameraX artifacts, binding use cases to a lifecycle owner, and wiring the preview pipeline using CameraXViewfinder or PreviewView for consistent behavior across devices.

Why does my Android camera capture deadlock after migrating to CameraX?

Camera capture deadlocks often occur when ImageProxy is not closed. Correct capture handling in CameraX uses ImageCapture so rotation is handled via ImageProxy, and emphasizes closing the proxy to avoid capture deadlocks.

How do I implement tap-to-focus in CameraX after replacing Camera1?

Implement tap-to-focus in CameraX by triggering focus and metering using CameraX APIs. This requires using metering point factories to replace manual camera logic for both Views and Jetpack Compose integrations.

What is the best way to handle Android camera lifecycle management across devices?

The best way to handle Android camera lifecycle management is using modern lifecycle-safe initialization with ProcessCameraProvider.bindToLifecycle tied to a LifecycleOwner, replacing manual camera open and close logic to reduce rotation bugs and handle device differences reliably.