0

I'm creating a face detection app. When I try to start the face detection, I get the following error:

E/NativeFaceDetectorImpl: Native face detection failed
E/NativeFaceDetectorImpl: java.lang.RuntimeException: Error accessing ByteBuffer.

Here's part of my code:

 Context context = getApplicationContext();
    FaceDetector detector = new FaceDetector.Builder(context)
            .setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
            .setMode(FaceDetector.ACCURATE_MODE)
            .build();

    detector.setProcessor(
            new MultiProcessor.Builder<>(new FaceTrackerFactory())
                    .build());

    if (!detector.isOperational()) {
        Log.w(TAG, "Face detector dependencies are not yet available.");
    }

    mCameraSource = new CameraSource.Builder(context, detector)
            .setFacing(CameraSource.CAMERA_FACING_BACK)
            .setRequestedFps(30.0f)
            .build();

The error is displayed when I do mCameraSource.start(), even though no error is detecting when doing so and the app doesn't crash, it simply display that error repeatedly on the console.

David Matos
  • 560
  • 2
  • 11
  • 24
  • 1
    What version of Android and Google Play Services are you using? I seem to recall that there was an issue like this in using Gingerbread and Google Play Services 7.8 together. If this is the same issue, it should be fixed if you use Google Play Services 8.1. – pm0733464 Oct 08 '15 at 14:34
  • I'm using Google Play Services version 8.1 and compiling for Android API 19, so I guess that's not the problem :/ – David Matos Oct 09 '15 at 09:44

1 Answers1

0

So I was able to figure out what the problem was. I was trying to compile for Android API 19 using the Mobile Vision API from version 8.1.0 of Google Play Services. This was in my build.gradle and it didn't work:

dependencies {
    compile 'com.google.android.gms:play-services-vision:8.1.0'
}

android {
    compileSdkVersion 19
}

I switchted to version 7.8 of Google Play Services and now it works fine.

dependencies {
    compile 'com.google.android.gms:play-services-vision:7.8.+'
}

android {
    compileSdkVersion 19
}

Also note that I had another similar project compiling for Android API 23 and for that version, Google Play Services 8.1 is working.

dependencies {
    compile 'com.google.android.gms:play-services-vision:8.1.0'
}

android {
    compileSdkVersion 23
}
David Matos
  • 560
  • 2
  • 11
  • 24