Android UnsatisfiedLinkError With Tesseract and OpenCV

放肆的年华 提交于 2019-12-10 22:26:02

问题


I have been trying to get OpenCV and the android version of tesseract (tess-two) to work with my android app. I am developing in Android Studio 1.4, the problem is that if I add the tess-two dependency alone, the app works fine and I can load the tess-two library fine. Next when I add the OpenCV dependency to the app, it breaks the support for the tess-two library and throws me this runtime error:

Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.app.ocrapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.app.ocrapp-1/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libpngt.so"
at java.lang.Runtime.loadLibrary(Runtime.java:366)
at java.lang.System.loadLibrary(System.java:989)
at com.googlecode.tesseract.android.TessBaseAPI.<clinit>(TessBaseAPI.java:43)
at com.app.ocrapp.util.Libraries.<clinit>(Libraries.java:12)

Once I remove the OpenCV libraries and dependency from the app, tess-two begins to work again.

Here is my OpenCV build.gradle:

apply plugin: 'android-library'

    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.2"

        defaultConfig {
            minSdkVersion 15
            targetSdkVersion 21
            versionCode 3000
            versionName "3.0.0"
        }

        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                res.srcDirs = ['res']
                aidl.srcDirs = ['src']
                jniLibs.srcDirs = ['oclibs']
            }
        }
    }

And here is my tess-two build.gradle:

apply plugin: 'android-library'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 21
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
            jniLibs.srcDirs = ['libs']
        }
    }
}

Also here is a picture of my project structure, each library is circled with their respective libs folders circled as well (containing the .so files): Project Structure

All help would be greatly appreciated. I have been trying to fix this for days now.

-----EDIT------

I have solved this issue and have posted a solution below.


回答1:


Okay so I finally figured it out. The OpenCV library had a folder named "arm64-v8a" inside the native libs folder and the tess-two library does not contain such a folder. This is a problem because the "arm64-v8a" folder will make the app run in 64 bit mode when there is no 64 bit library available for tesseract for android (tess-two), thus throwing the crash shown in the question.

To fix this, I simply excluded the "arm64-v8a" folder.

Inside your app build.gradle and inside defaultConfig add:

packagingOptions {
        exclude "lib/arm64-v8a/FILE_NAME.SO"
}

Now where it says FILE_NAME.so, replace that with the file name of one of the files inside your OpenCV "arm64-v8" folder. Add the exclude line as many times as required to exclude all files inside the arm64-v8 folder.



来源:https://stackoverflow.com/questions/33030900/android-unsatisfiedlinkerror-with-tesseract-and-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!