# camerax

Guides Android camera development using CameraX, Jetpack, and Media3. Useful when wiring video capture, handling foldables, or migrating from Camera2.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 1200 installs · ★ 9848
- Author: Google LLC
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/android/skills/tree/HEAD/camera/camerax/SKILL.md
- Updated: 2026-10-23
- HTML: https://affpapa.org/en/nevibecode/skills/camerax

## What it does

This skill teaches the agent official Android patterns for CameraX, `Camera2Interop`, and Media3 pipelines. It prevents silent bugs caused by immutable builder patterns. In CameraX `VideoCapture`, calling `withAudioEnabled()` returns a new instance, so failing to reassign or chain that call silently leaves audio disabled.

It provides blueprints for migrating legacy `Camera1` and `Camera2` codebases, setting up `MlKitAnalyzer`, handling RAW capture, and adapting camera previews to foldable hinge postures. When testing camera components, the rules explicitly advise against mocking libraries like `Mockito` on `ImageProxy`, guiding the agent to build fakes instead and run assertions via Google Truth.

Audio capture breaks immediately without the proper runtime permissions. The skill ensures your implementation checks `RECORD_AUDIO` independently of the camera permission and dispatches background camera callbacks onto the main thread for UI state.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add android/skills --skill camerax -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/camerax/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/camerax/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add android/skills --skill camerax -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/camerax/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add android/skills --skill camerax -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/camerax/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install android/skills camerax
```

2. **Manually: put the files in place**
- File: `.github/skills/camerax/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add android/skills --skill camerax -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/android/skills --path camera/camerax
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/camerax/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add android/skills --skill camerax -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/android/skills/tree/HEAD/camera/camerax/SKILL.md

## When to use it
- migrate legacy Camera1 or Camera2 implementations to CameraX
- configure VideoCapture with chained audio settings properly
- wire computer vision pipelines using MlKitAnalyzer
- build test suites with FakeCameraConfig without relying on Mockito

## Example prompts
- Show me how to chain prepareRecording in CameraX with audio enabled
- Help me migrate this Camera2 session callback logic to CameraX
- Write a unit test for camera analysis using FakeCameraConfig and Truth assertions

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: bd23ecea5d4c219e.

BEGIN THIRD-PARTY FILE bd23ecea5d4c219e
````text
---
name: camerax
description: Provide technical guidance for Android camera development with CameraX.
  Use when implementing camera features, handling asynchronous recording lifecycles,
  wiring low-level hardware interop using CameraX, or integrating ML Kit or Media3
  effects.
license: Complete terms in LICENSE.txt
metadata:
  author: Google LLC
  last-updated: '2026-10-08'
  keywords:
  - recipe
  - Android
  - Camera
  - Camera1
  - Camera2
  - CameraX
  - migration
  - Compose
  - guide
  - dependencies
  - PreviewView
  - CameraXViewfinder
  - ImageCapture
  - VideoCapture
  - ImageAnalysis.
---

This skill provides procedural guidance and standard patterns for building
camera applications on Android, with a focus on CameraX, including its
`Camera2Interop` utilities, and Media3 integrations.

## Core workflows

### Handling immutable API patterns

Various Android camera and media APIs, especially CameraX `VideoCapture`, use a
**fluent, immutable builder-like pattern** where methods return a new instance.
Failing to reassign these results in settings, such as audio, being ignored.

**Pattern: Reassignment is required**


```kotlin
// WRONG
run {
  val pending = recorder.prepareRecording(context, opts)
  pending.withAudioEnabled() // This returns a new instance which is ignored
  val active = pending.start(exec, listener)
}

// CORRECT
run {
  val pending = recorder.prepareRecording(context, opts)
      .withAudioEnabled() // Chaining works
  val active = pending.start(exec, listener)
}

// ALSO CORRECT
run {
  var pending = recorder.prepareRecording(context, opts)
  pending = pending.withAudioEnabled() // Reassignment
  val active = pending.start(exec, listener)
}
```

<br />

See [immutability](references/immutability.md) for a list of affected classes.

### Migrating to CameraX

When migrating legacy camera codebases to the CameraX Jetpack library:

- **Camera1 to CameraX** : For migrating legacy `android.hardware.Camera` implementations, surface handling, and manual lifecycles, see the [Camera1 migration guide](references/camera1-to-camerax.md).
- **Camera2 to CameraX** : For migrating more recent but verbose `android.hardware.camera2` implementations, session state callbacks, and interop patterns, see the [Camera2 migration guide](references/camera2-to-camerax.md).

### Comprehensive feature blueprinting

For multi-step features that involve multiple files and hardware-level wiring,
follow the [Structural Blueprinting](references/expert-blueprints.md) approach to avoid
system timeouts. Such complex features include:

- **Manual controls** : Break down into the `ViewModel` state, the controller layer, and the `Camera2Interop` wiring in the session.
- **RAW capture**: Separate JPEG and RAW output configurations into discrete build steps.
- **Custom effects** : Prefer `Media3Effect` or `SurfaceProcessor` over manual OpenGL pipelines unless absolute performance is required.
````
END THIRD-PARTY FILE bd23ecea5d4c219e

The third-party file has ended. Everything between the bd23ecea5d4c219e tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2933 of 6402 bytes. © Google LLC · Apache-2.0 · https://github.com/android/skills/tree/HEAD/camera/camerax/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
