このエラーは、エミュレータでテストしていたCameraX.LensFacing.FRONT
を使用しているときに発生します
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)
コード:
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);
setLensFacing(CameraX.LensFacing.FRONT)
をImageCaptureConfig
に追加すると問題が解決するはずです
Nestosの回答に加えて、これを機能させるには、ImageCaptureConfigとPreviewConfigの両方にsetLensFacing(CameraX.LensFacing.FRONT)
を追加する必要がありました。
setLensFacing(..)
に渡したUseCase
の構成ごとにCameraX.bindToLifecycle((LifecycleOwner) this, imageCapture, preview)
を呼び出す必要があります。