android / android/camera-samples

Use case binding failed

Open
#372 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
5.5k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

Device: Huawei P40 Lite E
dependencies:

```
//CameraX dependencies
def camerax_version = "1.1.0-alpha03"

//ML kit for computer vision, needed for face detection
//bundled with app
implementation 'com.google.mlkit:face-detection:16.0.6'

//CameraX core library using camera implementation
implementation "androidx.camera:camera-camera2:$camerax_version"
// CameraX Lifecycle Library
implementation "androidx.camera:camera-lifecycle:$camerax_version"
// CameraX View class
implementation "androidx.camera:camera-view:1.0.0-alpha23"
```

Stacktrace:

```
E/CameraManager: Use case binding failed
java.lang.IllegalArgumentException: No supported surface combination is found for camera device - Id : 0. May be attempting to bind too many use cases. Existing surfaces: [] New configs: [androidx.camera.core.impl.PreviewConfig@eec1a35, androidx.camera.core.impl.ImageAnalysisConfig@4817eca, androidx.camera.core.impl.ImageCaptureConfig@a00b83b]
at androidx.camera.lifecycle.LifecycleCameraRepository.bindToLifecycleCamera(LifecycleCameraRepository.java:278)
at androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle(ProcessCameraProvider.java:428)
at androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle(ProcessCameraProvider.java:302)
at -.lambda$startCamera$2$CameraManager(CameraManager.java:337)
at -.-$$Lambda$CameraManager$3Pt5AM_BPyOCEft3HHixQCAePBk.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:900)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8349)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
```

code:

```
// Unbind use cases before rebinding
cameraProvider.unbindAll();

//preview
Preview preview = new Preview.Builder()
.setTargetResolution(new Size(previewWidth, previewHeight))
.setTargetRotation(ROTATION_0) //ROTATION_90 // //rotation
.build();

preview.setSurfaceProvider(previewView.getSurfaceProvider());

//viewport defines the buffer rect visible to end users
final ViewPort viewPort = new ViewPort.Builder(new Rational(previewWidth, previewHeight), ROTATION_0).build(); //rotation

//picture callback
imageCapture = new ImageCapture.Builder()
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
.setBufferFormat(ImageFormat.YUV_420_888)
.setTargetResolution(new Size(pictureWidth, pictureHeight))
.setTargetRotation(ROTATION_0) //rotation
.build();

//face detection analysis
imageAnalysis = new ImageAnalysis.Builder()
//ensure that backpressure strategy is set to its default strategy for real-time analysis
.setBackpressureStrategy(STRATEGY_KEEP_ONLY_LATEST)
.setTargetResolution(new Size(previewWidth, previewHeight))
.setTargetRotation(ROTATION_0) //rotation
.build();

setFaceDetector(imageAnalysis, 0.05f); //0.1f

//use UseCaseGroup to assign viewport to use cases
UseCaseGroup useCaseGroup = new UseCaseGroup.Builder()
.addUseCase(preview)
.addUseCase(imageAnalysis)
.addUseCase(imageCapture)
.setViewPort(viewPort)
.build();

this.camera = cameraProvider.bindToLifecycle((LifecycleOwner) activity, cameraSelector, useCaseGroup); //preview, imageAnalysis, imageCapture
^^^^^^ fails here on this line ^^^^^^^
```

Specifically only fails on the Huawei phone, while e.g. OnePlus 5T, Pixel 3, Galaxy phones, I don't have this issue.

Contributor guide

Open the contributing guide

Research direction

Start at CameraManager.java around startCamera and the bindToLifecycle call at line 337, then review the CameraX dependencies and the Preview, ImageAnalysis, and ImageCapture configuration shown here. Reproduce on the Huawei P40 Lite E and compare with the listed working devices; done means the three use cases bind without the reported surface-combination exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.