camera1-to-camerax

Migrate legacy Camera1 or Camera2 code to CameraX with lifecycle binding.

6.6k|388|Updated Mar 16, 2026
One-click install
npx skills add https://github.com/android/skills --skill camera1-to-camerax-android
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: camera1-to-camerax
Source: https://github.com/android/skills/tree/main/camera/camera1-to-camerax
Command: npx skills add https://github.com/android/skills --skill camera1-to-camerax-android

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It removes the brittleness of legacy Camera1 and raw Camera2 code by guiding you through a reliable migration to CameraX for consistent orientation, lifecycle handling, and camera use-case wiring.

Core Features & Use Cases

  • Dependency setup for CameraX: Configure CameraX Core, Camera2 interop, lifecycle binding, and the appropriate preview/capture UI layer (View or Compose).
  • Lifecycle-aware camera binding: Replace manual open/close and custom lifecycle code with ProcessCameraProvider.bindToLifecycle so the camera follows your LifecycleOwner safely.
  • Preview, tap-to-focus, and capture modernization: Implement PreviewView (Views) or CameraXViewfinder (Compose), use FocusMeteringAction for tap-to-focus, and capture photos with ImageCapture while ensuring ImageProxy is closed.

Quick Start

Ask an AI assistant to migrate your existing Camera1 or Camera2 implementation in this project to CameraX by updating dependencies, replacing manual lifecycle camera code with ProcessCameraProvider, wiring Preview and tap-to-focus for your UI toolkit, and refactoring photo capture to use ImageCapture with proper ImageProxy closing.

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 Camera1 code to CameraX to fix lifecycle and rotation issues?

Migrating legacy Camera1 code to CameraX involves adding CameraX dependencies, replacing manual open/close logic with ProcessCameraProvider.bindToLifecycle, and implementing Preview and ImageCapture use cases to resolve lifecycle and rotation brittleness.

What's the best way to implement tap-to-focus using CameraX in an Android app?

Tap-to-focus in CameraX is implemented using FocusMeteringAction combined with your CameraX camera control instance. This modernizes focus handling by replacing legacy manual calculations with built-in metering regions during your Preview use case setup.

Does CameraX support both Jetpack Compose and traditional Android Views for camera preview?

Yes, CameraX supports both UI toolkits for camera preview. You can use PreviewView for traditional Android Views or CameraXViewfinder for Jetpack Compose, binding either implementation to a LifecycleOwner via ProcessCameraProvider.

Why does my CameraX ImageCapture implementation crash or freeze the camera feed?

CameraX ImageCapture crashes or camera feed freezes typically occur when the captured ImageProxy is not properly closed. You must ensure ImageProxy closure completes after image processing to release the camera buffer back to the pipeline.

How do I set up CameraX dependencies for a standard Android photo capture workflow?

Setting up CameraX dependencies requires including core, camera2, lifecycle, and the appropriate view or compose artifacts. This configuration enables ProcessCameraProvider binding, Preview display, and ImageCapture functionality for your photo capture workflow.