https://developer.android.com/agents/skills/camera/camera1-to-camerax/skill

Migrate Android Camera1 code to CameraX with lifecycle-aware preview and capture.

5|Updated Feb 22, 2026
One-click install
npx skills add https://github.com/fornewid/android-developers-changelog --skill https-developer-android-com-agents-skills-camera-camera1-to-camerax-skill
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: https://developer.android.com/agents/skills/camera/camera1-to-camerax/skill
Source: https://github.com/fornewid/android-developers-changelog/tree/main/docs/agents/skills/camera/camera1-to-camerax
Command: npx skills add https://github.com/fornewid/android-developers-changelog --skill https-developer-android-com-agents-skills-camera-camera1-to-camerax-skill

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Camera1 implementations are complex, tied to manual lifecycle handling, and often require brittle orientation and focus logic. This migration guide helps you replace those legacy camera APIs with CameraX components that integrate cleanly with Android lifecycles.

Core Features & Use Cases

  • Dependency setup for CameraX: Adds CameraX libraries using a Version Catalog or direct Gradle dependencies, with guidance to use minimum versions for interoperability and Compose extensions.
  • Lifecycle-safe camera initialization: Uses ProcessCameraProvider to bind Preview and ImageCapture to a LifecycleOwner instead of manually opening/closing the camera in onResume/onPause.
  • Preview and tap-to-focus: Supports both View-based (PreviewView + startFocusAndMetering) and Compose-based (CameraXViewfinder + metering via coordinate transforms) tap-to-focus patterns.
  • Photo capture and rotation handling: Captures via ImageCapture.takePicture, processes ImageProxy rotation degrees, mirrors the front camera output, and ensures image.close() is called.
  • Switching cameras: Reconfigures CameraSelector (front/back) and re-runs the binding flow.

Quick Start

Ask the AI to migrate my existing Android android.hardware.Camera + SurfaceView code to CameraX with ProcessCameraProvider, Preview, ImageCapture, and tap-to-focus for my UI toolkit (Views or Compose), then provide the exact Kotlin snippets and constraints to follow.

Frequently Asked Questions about https://developer.android.com/agents/skills/camera/camera1-to-camerax/skill

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

FAQPage Schema
How do I migrate my Android Camera1 code to CameraX using ProcessCameraProvider?

To migrate Camera1 to CameraX, replace manual lifecycle and surface callbacks with CameraX use cases. Bind Preview and ImageCapture to a LifecycleOwner via ProcessCameraProvider, and use PreviewView or CameraXViewfinder for lifecycle-safe camera initialization.

How does tap-to-focus work when migrating to CameraX with Jetpack Compose?

Tap-to-focus in Jetpack Compose uses CameraXViewfinder combined with metering via coordinate transforms. For View-based UIs, it uses PreviewView and calls startFocusAndMetering to handle the focus interaction based on user taps.

Can I use CameraX for photo capture and handle front camera image rotation?

CameraX handles photo capture using ImageCapture.takePicture, processing ImageProxy rotation degrees. It mirrors front camera output and requires explicitly calling image.close() on the ImageProxy to prevent memory leaks.

Do I need to manually open and close the camera in onResume and onPause with CameraX?

No, CameraX eliminates manual camera opening and closing in onResume and onPause. By binding Preview and ImageCapture to a LifecycleOwner through ProcessCameraProvider, the camera lifecycle is managed automatically.

What's the best way to switch between front and back cameras in CameraX?

Switching cameras in CameraX requires reconfiguring the CameraSelector between front and back lenses, then re-running the binding flow with ProcessCameraProvider. This rebinds your Preview and ImageCapture use cases to the newly selected camera.

What CameraX dependencies do I need to add for an Android camera migration?

For a CameraX migration, you need to add Core, Camera2, and Lifecycle dependencies, plus View or Compose extensions depending on your UI toolkit. These can be added using a Version Catalog or direct Gradle dependencies.