This error occurs when using CameraX.LensFacing.FRONT
, was testing on an emulator
E/AndroidRuntime: FATAL EXCEPTION: main
Process: meter.meter, PID: 15289
java.lang.RuntimeException: Unable to start activity ComponentInfo{meter.meter/meter.meter.CameraActivity}: java.lang.IllegalArgumentException: Suggested resolution map missing resolution for camera 1
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalArgumentException: Suggested resolution map missing resolution for camera 1
at androidx.camera.core.Preview.onSuggestedResolutionUpdated(Preview.java:310)
at androidx.camera.core.UseCase.updateSuggestedResolution(UseCase.java:375)
at androidx.camera.core.CameraX.calculateSuggestedResolutions(CameraX.java:458)
at androidx.camera.core.CameraX.bindToLifecycle(CameraX.java:144)
at meter.meter.CameraActivity.onCreate(CameraActivity.java:68)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
Code:
PreviewConfig config = new PreviewConfig.Builder().setLensFacing(CameraX.LensFacing.FRONT).build();
Preview preview = new Preview(config);
TextureView textureView = findViewById(R.id.textureView);
preview.setOnPreviewOutputUpdateListener(new Preview.OnPreviewOutputUpdateListener() {
@Override
public void onUpdated(Preview.PreviewOutput output) {
textureView.setSurfaceTexture(output.getSurfaceTexture());
}
});
ImageCaptureConfig imageCaptureConfig = new ImageCaptureConfig.Builder().build();
imageCapture = new ImageCapture(imageCaptureConfig);
CameraX.bindToLifecycle((LifecycleOwner) this,imageCapture, preview);
You should call setLensFacing(..)
for each Config of UseCase
that you passed to
CameraX.bindToLifecycle((LifecycleOwner) this, imageCapture, preview)
PreviewConfig ImageCaptureConfig ImageAnalysisConfig All need to be added
setLensFacing(CameraX.LensFacing.FRONT)
This is how I set it up
add setLensFacing(CameraX.LensFacing.FRONT)
to ImageCaptureConfig
should solve your problem
As an addition to nestos answer, I had to add setLensFacing(CameraX.LensFacing.FRONT)
to both ImageCaptureConfig and PreviewConfig to make this work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With