找不到“libjniopencv_core.so”

时间:2017-05-16 13:59:52

标签: java android opencv

我正在使用opencv开发一个Android应用程序而且我遇到了问题......

我遇到的错误是:

FATAL EXCEPTION: AsyncTask #3
     Process: com.sogeti.innovation.obcapture, PID: 29681
     java.lang.RuntimeException: An error occurred while executing doInBackground()
         at android.os.AsyncTask$3.done(AsyncTask.java:309)
         at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
         at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
         at java.util.concurrent.FutureTask.run(FutureTask.java:242)
         at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
         at java.lang.Thread.run(Thread.java:818)
      Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.sogeti.innovation.obcapture-1/base.apk"],nativeLibraryDirectories=[/data/app/com.sogeti.innovation.obcapture-1/lib/arm, /data/app/com.sogeti.innovation.obcapture-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]] couldn't find "libjniopencv_core.so"
         at java.lang.Runtime.loadLibrary(Runtime.java:367)
         at java.lang.System.loadLibrary(System.java:1076)
         at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:804)
         at org.bytedeco.javacpp.Loader.load(Loader.java:613)
         at org.bytedeco.javacpp.Loader.load(Loader.java:530)
         at org.bytedeco.javacpp.opencv_core.<clinit>(opencv_core.java:10)
         at java.lang.Class.classForName(Native Method)
         at java.lang.Class.forName(Class.java:324)
         at org.bytedeco.javacpp.Loader.load(Loader.java:585)
         at org.bytedeco.javacpp.Loader.load(Loader.java:530)
         at org.bytedeco.javacpp.helper.opencv_core$AbstractArray.<clinit>(opencv_core.java:109)
         at com.sogeti.innovation.obcapture.bl.mobile.alg.ImageProcessingHelper.liveProcessImage(ImageProcessingHelper.java:46)
         at com.sogeti.innovation.obcapture.bl.LiveProcessImage.doInBackground(LiveProcessImage.java:35)
         at com.sogeti.innovation.obcapture.bl.LiveProcessImage.doInBackground(LiveProcessImage.java:21)
         at android.os.AsyncTask$2.call(AsyncTask.java:295)
         at java.util.concurrent.FutureTask.run(FutureTask.java:237)
         at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
         at java.lang.Thread.run(Thread.java:818) 
      Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.sogeti.innovation.obcapture-1/base.apk"],nativeLibraryDirectories=[/data/app/com.sogeti.innovation.obcapture-1/lib/arm, /data/app/com.sogeti.innovation.obcapture-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]] couldn't find "libopencv_imgproc.so"
         at java.lang.Runtime.loadLibrary(Runtime.java:367)
         at java.lang.System.loadLibrary(System.java:1076)
         at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:804)
         at org.bytedeco.javacpp.Loader.load(Loader.java:604)
         at org.bytedeco.javacpp.Loader.load(Loader.java:530) 
         at org.bytedeco.javacpp.opencv_core.<clinit>(opencv_core.java:10) 
         at java.lang.Class.classForName(Native Method) 
         at java.lang.Class.forName(Class.java:324) 
         at org.bytedeco.javacpp.Loader.load(Loader.java:585) 
         at org.bytedeco.javacpp.Loader.load(Loader.java:530) 
         at org.bytedeco.javacpp.helper.opencv_core$AbstractArray.<clinit>(opencv_core.java:109) 
         at com.sogeti.innovation.obcapture.bl.mobile.alg.ImageProcessingHelper.liveProcessImage(ImageProcessingHelper.java:46) 
         at com.sogeti.innovation.obcapture.bl.LiveProcessImage.doInBackground(LiveProcessImage.java:35) 
         at com.sogeti.innovation.obcapture.bl.LiveProcessImage.doInBackground(LiveProcessImage.java:21) 
         at android.os.AsyncTask$2.call(AsyncTask.java:295) 
         at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
         at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
         at java.lang.Thread.run(Thread.java:818)

以下是 build.graddle 文件包含的内容:

import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.application'


android {
    compileSdkVersion 24
    buildToolsVersion '25.0.2'

    defaultConfig {
        applicationId "com.sogeti.innovation.obcapture"
        minSdkVersion 19
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        jackOptions {
            enabled false
            additionalParameters("jack.incremental" : "true")
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
        pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
        pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
        pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
        pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
        pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/1.2/javacpp-presets-1.2.pom.xml'
        pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/org.bytedeco.javacpp-presets-1.2.pom.xml'
    }
}

dependencies {
    compile files('libs/javacpp-1.3.jar')
    compile files('libs/javacv-1.3.jar')
    compile files('libs/opencv-3.1.0-1.3-android-arm.jar')
    compile files('libs/opencv-3.1.0-1.3.jar')
    compile files('libs/ffmpeg-3.2.1-1.3-android-arm.jar')
    compile files('libs/ffmpeg-3.2.1-1.3.jar')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/maps.jar')
    compile "com.android.support:appcompat-v7:24.1.1"
    compile "com.android.support:cardview-v7:24.1.1"
    compile "com.android.support:recyclerview-v7:24.1.1"
    compile "com.android.support:design:24.1.1"
    compile "com.android.support:support-v4:24.1.1"
    compile 'com.google.android.gms:play-services:9.0.2'
    compile 'com.github.bluejamesbond:textjustify-android:2.1.1'
    compile 'com.google.android.gms:play-services-ads:9.0.2'
    compile 'com.google.android.gms:play-services-identity:8.4.0'
    compile 'com.google.android.gms:play-services-gcm:9.0.2'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.squareup.okio:okio:1.8.0'
    compile 'commons-codec:commons-codec:1.9'
    compile 'com.google.android.gms:play-services-auth:9.0.2'
    compile 'com.android.support:multidex:1.0.1'
    compile 'org.florescu.android.rangeseekbar:rangeseekbar-library:0.3.0'
    compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1'

    compile project(':common')
    compile project(':commonwidget')
    compile project(':panowidget')
    compile project(':base')
}

这是 settings.graddle 文件:

include ':app', ":common", ":commonwidget", ":panowidget", ":base"

在我添加“base”包之前,一切正常。

先谢谢你的帮助:D

编辑:感谢@Prateek的回答,我创建了JNILibs文件夹,然后添加了所需的.so文件。但是有一个问题,因为我没有所需的所有版本(arm64-v8a,armeabi,armeabi-v7a ......),尤其是关于我的手机的版本。所以我试着从这里下载它,但文件不是共享对象.so但是静态.a所以它不起作用...任何人都可以帮助我吗? :)

解决方案:我只有32位版本的库文件“.so”。所以我所做的就像@Prateek所说的那样,将这些文件放在文件夹“JNILibs”的子文件夹“armeabi”,“armeabi-v7a”,“mips”和“x86”中。然后我通过在“build.graddle”app文件中添加 ndk 规范强制使用32位文件,如下所示。

    android {
       compileSdkVersion 24
       buildToolsVersion '25.0.2'

       defaultConfig {
          applicationId "com.sogeti.innovation.obcapture"
          minSdkVersion 19
          targetSdkVersion 22
          versionCode 1
          versionName "1.0"
          multiDexEnabled true
          jackOptions {
             enabled false
             additionalParameters("jack.incremental" : "true")
          }

         ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
         }
       }
    }

希望它可以帮助某人:)

1 个答案:

答案 0 :(得分:0)

你把libjniopencv_core.so文件放在JNI文件夹中了吗?