{"record":{"id":"acfff5c90966f619","repo":"microg/GmsCore","slug":"could-not-find-suitable-preview-size","errorCode":null,"errorMessage":"Could not find suitable preview size.","messagePattern":"Could not find suitable preview size\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"play-services-vision-common/src/main/java/com/google/android/gms/vision/CameraSource.java","lineNumber":405,"sourceCode":"        if (sizeCandidates.size() == 0) {\n            for (Camera.Size previewSize : camera.getParameters().getSupportedPreviewSizes()) {\n                sizeCandidates.add(new SizePair(previewSize, null));\n            }\n        }\n\n        SizePair sizePair = null;\n        int selectedSizeOffset = Integer.MAX_VALUE;\n        int sizeOffset;\n        for (SizePair candidate : sizeCandidates) {\n            Size candidatePreviewSize = candidate.preview;\n            sizeOffset = Math.abs(candidatePreviewSize.getWidth() - requestedWidth) + Math.abs(candidatePreviewSize.getHeight() - requestedHeight);\n            if (sizeOffset < selectedSizeOffset) {\n                sizePair = candidate;\n                selectedSizeOffset = sizeOffset;\n            }\n        }\n\n        if (sizePair == null) throw new IOException(\"Could not find suitable preview size.\");\n        return sizePair;\n    }\n\n    private static class SizePair {\n        Size preview;\n        Size picture;\n\n        public SizePair(Camera.Size preview, Camera.Size picture) {\n            this.preview = new Size(preview.width, preview.height);\n            if (picture != null) {\n                this.picture = new Size(picture.width, picture.height);\n            }\n        }\n    }\n\n    private class DetectorRunner implements Runnable {\n        private final Object lock = new Object();\n        private long startElapsedRealtime = SystemClock.elapsedRealtime();","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-vision-common/src/main/java/com/google/android/gms/vision/CameraSource.java#L387-L423","documentation":"Camera negotiation failure in CameraSource.pickCameraSize: none of the camera's supported preview/picture size candidates could be matched to the requested dimensions, so no preview size can be selected on this device.","triggerScenarios":"Thrown at play-services-vision-common/src/main/java/com/google/android/gms/vision/CameraSource.java:405 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Request a more common preview resolution (e.g. 640x480) supported by the device","Pick the closest match manually from getSupportedPreviewSizes()","Catch the exception and fall back to a default size or disable camera detection"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"157c9d86ac46c195a86c2f15ab55c84036223f95","analyzedAt":"2026-09-06T17:27:33.892Z","contentChangedAt":"2026-09-06T17:27:33.892Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}