microg/GmsCore · critical · RuntimeException
faceDetectorYN initialization failed
Error message
faceDetectorYN initialization failed
What it means
FaceDetectorHelper's constructor loads an ONNX face-detection model from assets and calls OpenCV FaceDetectorYN.create; any exception during model load/creation is rethrown as this RuntimeException. It means the bundled DNN model could not be initialized, so face detection is unusable.
Source
Thrown at play-services-vision/core/src/main/kotlin/org/microg/gms/vision/face/FaceDetectorHelper.kt:50
const val TAG = "FaceDetection"
class FaceDetectorHelper(context: Context) {
private var faceDetectorYN: FaceDetectorYN? = null
private var inputSize = Size(320.0, 320.0)
init {
try {
val buffer: ByteArray
context.assets.open("face_detection_yunet_2023mar.onnx").use {
val size = it.available()
buffer = ByteArray(size)
it.read(buffer)
}
faceDetectorYN = FaceDetectorYN.create("onnx", MatOfByte(*buffer), MatOfByte(), inputSize, 0.7f, 0.3f, 5000)
} catch (e: Exception) {
throw RuntimeException("faceDetectorYN initialization failed")
}
}
fun detectFaces(bitmap: Bitmap, rotation: Int): List<FaceParcel> {
Log.d(TAG, "detectFaces: source is bitmap")
val rootMat = bitmapToMat(bitmap) ?: return emptyList()
return processMat(rootMat, rotation)
}
fun detectFaces(nv21ByteArray: ByteArray, width: Int, height: Int, rotation: Int): List<FaceParcel> {
Log.d(TAG, "detectFaces: source is nv21Buffer")
val rootMat = nv21ToMat(nv21ByteArray, width, height) ?: return emptyList()
return processMat(rootMat, rotation)
}
fun detectFaces(image: Image, rotation: Int): List<FaceParcel> {
Log.d(TAG, "detectFaces: source is image")
val rootMat = imageToMat(image) ?: return emptyList()View on GitHub (pinned to 157c9d86ac)
Solutions
- Verify the onnx model file exists in src/main/assets (or wherever `assets.open` reads it) and is not truncated.
- Ensure your OpenCV dependency is >= 4.5.1 and includes the dnn module.
- Log the original exception (`throw RuntimeException("faceDetectorYN initialization failed", e)`) to see the root cause before blaming config.
- Reduce/validate inputSize and try the default 300x300; test FaceDetectorYN.create in isolation.
Example fix
// before
} catch (e: Exception) {
throw RuntimeException("faceDetectorYN initialization failed")
}
// after
} catch (e: Exception) {
throw RuntimeException("faceDetectorYN initialization failed", e)
} Defensive patterns
Strategy: validation
Validate before calling
val model = assets.list("")?.contains("onnx") ?: false
if (!model || !OpenCVLoader.initDebug()) failFast("OpenCV/model unavailable") Try / catch
try {
val detector = FaceDetector(context)
} catch (e: RuntimeException) {
Log.e(TAG, "Face detection unavailable: ${e.message}", e)
disableFeature()
} Prevention
- Verify the onnx asset ships in the APK (check build output)
- Use OpenCV >= 4.5.1 with dnn module
- Fail fast at app start, not mid-frame
- Log root causes (wrap the original exception)
When it happens
Trigger: Constructing FaceDetector (which instantiates FaceDetectorHelper) when the model asset is missing/corrupt, asset read fails, inputSize is invalid, or OpenCV's DNN module can't parse the onnx model.
Common situations: OpenCV dependency without dnn/onnx support; corrupt or truncated asset file; too-large inputSize for available memory; mismatched OpenCV version lacking FaceDetectorYN.
Related errors
- Access denied, missing google package permission for
- Required caller information missing
- ERROR_MISSING_INSTANCEID_SERVICE
- Unable to find dynamic class com.google.android.gms.maps.int
- Unable to call the default constructor of com.google.android
AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06).
Data as JSON: /api/errors/997e25fd9723cf41.
Report an issue: GitHub.