opencvface-recognitionjavacv

JavaCV error in the AndroidStudio java.lang.NoClassDefFoundError: java.lang.ClassNotFoundException: org.bytedeco.javacpp.opencv_core


I am working on a face recognition system using JavaCV. I am using both OpenCV and JavaCV. I am also using AndroidStudio. However, it shows me this error.

12-20 00:22:25.315 6018-6018/com.example.nasif.xiomi_face E/AndroidRuntime: FATAL EXCEPTION: main
                                                                            Process: com.example.nasif.xiomi_face, PID: 6018
                                                                            java.lang.NoClassDefFoundError: java.lang.ClassNotFoundException: org.bytedeco.javacpp.opencv_core
                                                                                at org.bytedeco.javacpp.Loader.load(Loader.java:590)
                                                                                at org.bytedeco.javacpp.Loader.load(Loader.java:530)
                                                                                at org.bytedeco.javacpp.opencv_core$MatVector.<clinit>(opencv_core.java:475)
                                                                                at com.example.nasif.xiomi_face.Myjavacvface.training_facerecognition(Myjavacvface.java:58)
                                                                                at com.example.nasif.xiomi_face.MainActivity.onOptionsItemSelected(MainActivity.java:148)
                                                                                at android.app.Activity.onMenuItemSelected(Activity.java:2644)
                                                                                at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:368)
                                                                                at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:195)

Build gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.nasif.xiomi_face"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    // add
    compile 'com.google.android.gms:play-services-vision:11.6.2'
    compile 'org.bytedeco:javacv:1.1'
    compile 'org.bytedeco.javacpp-presets:opencv:3.0.0-1.1'

    implementation files('libs/jxl-2.6.12.jar')
    implementation project(':openCVLibrary24134')

}

Could you help me to solve this problem. Thank you.


Solution

  • If anyone has similar problem then solution is: add this 3 line in gradle then build it.

    compile 'org.bytedeco:javacv:1.3.3'   
    compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.2.0-1.3', classifier: 'android-arm'
    compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier: 'android-arm'
    

    Alternative:

      compile 'org.bytedeco:javacv:1.1'
      compile 'org.bytedeco.javacpp-presets:opencv:3.0.0-1.1:android-arm'
      compile 'org.bytedeco.javacpp-presets:ffmpeg:2.8.1-1.1:android-arm'