camera1-to-camerax

Migrates legacy Camera1 or Camera2 implementations to lifecycle-aware CameraX with Preview and ImageCapture.

8|1|Updated Mar 30, 2026
One-click install
npx skills add https://github.com/drewid74/ai_skills --skill camera1-to-camerax-drewid74
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: camera1-to-camerax
Source: https://github.com/drewid74/ai_skills/tree/main/android-camera1-to-camerax
Command: npx skills add https://github.com/drewid74/ai_skills --skill camera1-to-camerax-drewid74

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill fixes fragile, orientation- and lifecycle-buggy legacy Android camera implementations by migrating Camera1 or raw Camera2 usage to CameraX, which is lifecycle-aware and device-tolerant.

Core Features & Use Cases

  • Dependency setup: Adds the correct CameraX artifacts (including Compose support) with appropriate minimum versions.
  • Lifecycle-safe binding: Replaces manual camera open/close logic by binding use cases to a LifecycleOwner via ProcessCameraProvider.
  • Reliable preview and capture: Implements Preview plus ImageCapture, including tap-to-focus and correct rotation handling.
  • Front/back switching: Rebinds use cases when changing CameraSelector for lens-facing toggles.
  • Use Case: Migrate an app that currently manages android.hardware.Camera with custom SurfaceView + orientation matrices into a stable CameraX implementation with preview and photo capture.

Quick Start

Update your legacy Camera1/Camera2 implementation by following the CameraX steps to bind Preview and ImageCapture to your LifecycleOwner, wire PreviewView or CameraXViewfinder, add tap-to-focus, and capture photos without manual lifecycle or rotation handling.

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 for lifecycle-aware preview and capture?

Migrate legacy Camera1 code to CameraX by adding the correct CameraX dependencies, using ProcessCameraProvider to bind Preview and ImageCapture use cases to a LifecycleOwner, and replacing manual camera open/close logic with lifecycle-safe bindings.

What's the best way to implement tap-to-focus when migrating to CameraX?

Implement tap-to-focus during CameraX migration using MeteringPointFactory or SurfaceOrientedMeteringPointFactory to handle metering, ensuring accurate focus interactions within both PreviewView and Jetpack Compose CameraXViewfinder implementations.

Does CameraX work with Jetpack Compose for image capture and camera preview?

CameraX works with Jetpack Compose by wiring CameraXViewfinder for the preview display, binding it through ProcessCameraProvider, and capturing photos via ImageCapture with an ImageProxy closure to handle the captured image data.

How do I switch front and back camera lenses in CameraX without crashing the preview?

Switch front and back camera lenses in CameraX by updating the CameraSelector and rebinding the Preview and ImageCapture use cases to the LifecycleOwner via ProcessCameraProvider, ensuring the preview remains stable during the transition.

Why does my CameraX image capture have incorrect rotation after migrating from Camera1?

Incorrect rotation occurs when manual orientation matrices from Camera1 are not replaced; CameraX handles rotation automatically through ImageCapture, ensuring correct orientation behavior when properly bound to a LifecycleOwner.

Can I use CameraX if my app currently uses raw Camera2 with custom SurfaceView implementations?

You can migrate from raw Camera2 with custom SurfaceView to CameraX by replacing manual camera logic with ProcessCameraProvider bindings, utilizing PreviewView, and leveraging CameraX's device-tolerant, lifecycle-aware architecture for stable preview and capture.