camera1-to-camerax

Migrate legacy Android Camera1 code to lifecycle-aware CameraX with Preview and ImageCapture.

2|Updated Apr 26, 2026
One-click install
npx skills add https://github.com/iadr-dev/colab --skill camera1-to-camerax-iadr-dev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: camera1-to-camerax
Source: https://github.com/iadr-dev/colab/tree/main/skills/coding/android/camera/camera1-to-camerax
Command: npx skills add https://github.com/iadr-dev/colab --skill camera1-to-camerax-iadr-dev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Legacy Android camera implementations often break with device-specific rotation, lifecycle changes, and dependency quirks, making reliable preview and capture difficult to maintain.

Core Features & Use Cases

  • CameraX Dependency Setup: Adds the required CameraX libraries for Camera2-backed CameraX functionality, including lifecycle and preview/capture components.
  • Lifecycle-Aware Initialization: Binds Preview and ImageCapture to a LifecycleOwner via ProcessCameraProvider instead of manual camera open/close.
  • Preview, Tap-to-Focus, and Capture: Implements Preview (Views via PreviewView or Compose via CameraXViewfinder) with tap-to-focus using metering points and performs photo capture using ImageCapture while correctly handling ImageProxy rotation and closing.
  • Switching Cameras: Supports front/rear switching by rebuilding the CameraSelector and rebinding use cases.

Quick Start

Ask the AI to migrate your current Camera1 (or raw Camera2) preview and capture code to CameraX while preserving tap-to-focus and fixing rotation by binding Preview and ImageCapture to your Activity or Fragment lifecycle.

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 Android Camera1 code to CameraX for lifecycle-aware preview and capture?

Migrate Camera1 code to CameraX by replacing manual camera open/close calls with ProcessCameraProvider, binding Preview and ImageCapture use cases to a LifecycleOwner for stable resource management across configuration changes.

How does CameraX handle tap-to-focus and correct orientation during image capture?

CameraX handles tap-to-focus using metering points derived from PreviewView or CameraXViewfinder coordinates, and manages correct orientation by applying rotation metadata to ImageCapture output while ensuring proper ImageProxy closure.

Can I use CameraX with Jetpack Compose for camera preview and photo capture?

Yes, CameraX works with Jetpack Compose by implementing CameraXViewfinder for the preview surface and binding ImageCapture to the composable's LifecycleOwner, enabling reliable photo capture without manual lifecycle management.

What is the best way to switch front and rear cameras in CameraX without restarting the preview?

Switching cameras in CameraX requires rebuilding the CameraSelector for the desired lens facing direction and rebinding the Preview and ImageCapture use cases to ProcessCameraProvider.

Why does my legacy Android camera break on rotation and configuration changes?

Legacy Android camera implementations break on rotation because they lack lifecycle-aware initialization, requiring migration to CameraX to bind camera use cases directly to Activity or Fragment lifecycle for stable resource management.

What CameraX dependencies do I need for a Camera2-backed implementation with still capture?

A Camera2-backed CameraX implementation requires adding the CameraX core, camera2, and lifecycle libraries to your project to enable ProcessCameraProvider binding with Preview and ImageCapture components.