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

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

我正在使用 JavaCV 开发人脸识别系统。我同时使用 OpenCV 和 JavaCV。我也在使用 AndroidStudio。 但是,它向我显示了这个错误。

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)

建造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')

}

你能帮我解决这个问题吗?谢谢你。

如果有人遇到类似问题,那么解决方案是:在 gradle 中添加这 3 行,然后构建它。

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'

选择:

  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'