Index of every page on this site: llms.txt
All skills
android avatar

/camerax

@7f7b217
by androidandroid/skills11k stars
703
Run it yourself

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.

Use this Skill: https://skilld.dev/gh/android/skills/camerax

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencestesting.md

≈652 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Automated testing for camera features is notoriously difficult because you can't easily mock physical hardware, lighting, or motion. This guide provides patterns for reliable, hermetic camera tests.

Develop a testing mindset

Challenge Conventional approach Camera technical approach
Frameworks Mockito or MockK Fakes over mocks
Assertions assertEquals, assertTrue Google Truth, assertThat
Environment Implied environments Explicit @RunWith annotations
Async operations Thread.sleep Explicit timeoutMillis or IdlingResource

Follow the implementation guide

Fakes over mocks

Don't use Mockito. Relying on mocks for complex, rapidly changing interfaces like ImageProxy or CameraInfo makes tests brittle. Instead, build "Fake" implementations that verify state rather than behavior.

// Create a Fake ImageProxy for ML Testing (Fakes over Mocks)
val fakeImage = FakeImageProxy(w = 640, h = 480)

// Feed the fake buffer into your analyzer
<br />

Mock camera capabilities

Use FakeAppConfig from androidx.camera:camera-testing to simulate specific hardware constraints in tests, such as a device without a flash.

// Use awaitInstance() extension function for coroutine-based provider retrieval
val cameraProvider = ProcessCameraProvider.awaitInstance(context)
<br />

Use Truth assertions

Use Google Truth, assertThat, instead of standard JUnit assertions. It provides more readable assertion chains and useful failure messages.

Test asynchronous lifecycles

Camera initialization is asynchronous. Use IdlingResource to ensure your test waits for the UseCase to be bound before asserting.

To test asynchronous lifecycles, use the following pattern:

  1. Wrap the ProcessCameraProvider initialization in a CountDownLatch or IdlingResource.
  2. Assert only after the cameraControl instance is non-null.

Testing pitfalls

  • Resource leaks : To prevent "Camera in Use" errors, in your @After block, call cameraProvider.unbindAll.
  • The "flaky initializer": Camera tests often fail on CI because the "Virtual Camera" takes too long to warm up. Use a sufficient explicit timeout for the first initialization.
  • Permission blockers : To bypass the system permission dialogs, in your Espresso tests, use GrantPermissionRule.
  • Resolution mismatch : Tests on emulators often default to 640x480. Ensure your ResolutionSelector handles this low-res fallback correctly.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts6d3 checks · Risk SAFE
  • Gen Agent Trust Hub7d

    The skill provides technical guidance for Android CameraX development, covering migration from legacy APIs, handling device diversity (foldables, Wear OS, XR), and integrating with ML Kit and Media3. No security issues were detected; all code snippets and external references originate from trusted sources and follow standard platform patterns.

  • Socket6d

    No alerts

  • Snyk7d

    Risk: LOW · No issues

Signed by skilld at 7f7b217. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 1 hour ago.

Activeupdated last week
Other metadata
metadata
{
  "author": "Google LLC",
  "last-updated": "2026-11-10",
  "keywords": [
    "recipe",
    "Android",
    "Camera",
    "Camera1",
    "Camera2",
    "CameraX",
    "migration",
    "Compose",
    "guide",
    "dependencies",
    "PreviewView",
    "CameraXViewfinder",
    "ImageCapture",
    "VideoCapture",
    "ImageAnalysis."
  ]
}

README badge

README badge for android/skills/camerax