camerax

Implement Android camera features with CameraX, Camera2Interop, ML Kit, and Media3.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Building Android camera apps involves verbose Camera2 boilerplate, tricky asynchronous lifecycles, immutable builder APIs that silently drop settings, and hardware diversity across phones, foldables, Wear OS, and XR devices. This Skill provides proven CameraX patterns and migration guides that prevent common pitfalls like blocked capture pipelines and misaligned ML Kit overlays.

Core Features & Use Cases

  • Camera1/Camera2 Migration: Step-by-step guides to replace legacy camera code with lifecycle-bound CameraX use cases like Preview, ImageCapture, and ImageAnalysis.
  • Advanced Feature Blueprints: Phased implementation plans for manual controls (ISO, exposure, focus via Camera2Interop), RAW capture, low-light boost, and Media3 effects.
  • Form Factor Guidance: Patterns for foldables, Wear OS remote viewfinders, XR passthrough, thermal management, and hermetic camera testing with fakes.
  • Use Case: You need to add tap-to-focus and photo capture to a Jetpack Compose app. The Skill guides you to use CameraXViewfinder with SurfaceRequest, MeteringPointFactory for focus, and proper ImageProxy handling with rotation and mirroring.

Quick Start

Ask your agent to implement a CameraX photo capture feature with preview and tap-to-focus in your Android app.

Frequently Asked Questions about camerax

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

FAQPage Schema
How do I migrate from Camera2 to CameraX?

Replace CameraDevice and CameraCaptureSession callbacks with ProcessCameraProvider and bindToLifecycle. Delete manual HandlerThread management, surface routing, and orientation math, then map ImageReader flows to the ImageCapture and ImageAnalysis use cases.

How do I implement tap-to-focus in Jetpack Compose with CameraX?

Use CameraXViewfinder with a SurfaceRequest and CoordinateTransformer to map tap offsets to surface coordinates. Create a metering point with SurfaceOrientedMeteringPointFactory and call cameraControl.startFocusAndMetering with a FocusMeteringAction.

Why is audio missing from my CameraX video recording?

PendingRecording.withAudioEnabled returns a new instance that must be reassigned or chained. Calling it without reassignment silently ignores the setting, so chain it directly after prepareRecording or reassign the variable before calling start.

Can I use Camera2 features like manual ISO with CameraX?

Yes, use Camera2Interop.Extender to set CaptureRequest keys such as SENSOR_SENSITIVITY, SENSOR_EXPOSURE_TIME, and LENS_FOCUS_DISTANCE on CameraX builders. Set CONTROL_AE_MODE to OFF when manual exposure is active.

Why does my camera pipeline freeze after taking a photo?

The ImageProxy was not closed in the capture or analysis callback. Always call image.close() after processing, otherwise the capture pipeline locks and subsequent photos or analysis frames are blocked.

Should I use Mockito to test CameraX camera features?

No, prefer fakes over mocks because interfaces like ImageProxy are complex and brittle to mock. Use FakeCameraConfig from androidx.camera:camera-testing, Google Truth assertions, explicit RunWith annotations, and GrantPermissionRule for Espresso tests.