带有Tesseract和OpenCV的Android UnsatisfiedLinkError [英] Android UnsatisfiedLinkError With Tesseract and OpenCV

查看:158
本文介绍了带有Tesseract和OpenCV的Android UnsatisfiedLinkError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试获取OpenCV和tesseract的android版本(tess-two)与我的android应用程序一起使用.我正在Android Studio 1.4中进行开发,问题是,如果我仅添加tess-two依赖项,则该应用程序可以正常运行,并且可以很好地加载tess-two库.接下来,当我将OpenCV依赖项添加到应用程序时,它将破坏对tess-two库的支持,并向我抛出此运行时错误:

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)

一旦我从应用程序中删除了OpenCV库和依赖项,tess-two将再次开始工作.

这是我的 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']
            }
        }
    }

这是我的 tess-两个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']
        }
    }
}

这也是我的项目结构的图片,每个库都被圈了起来,各自的libs文件夹也被圈了起来(包含.so文件): 项目结构

所有帮助将不胜感激.我已经尝试了好几天了.

----- 编辑 ------

我已经解决了这个问题,并在下面发布了解决方案.

解决方案

好的,所以我终于弄清楚了. OpenCV库在本机libs文件夹内有一个名为"arm64-v8a"的文件夹,而tess-two库不包含此类文件夹. 这是一个问题,因为当没有适用于Android的tesseract的64位库(tess-two)可用时,"arm64-v8a"文件夹将使应用程序以64位模式运行,从而引发问题中显示的崩溃. >

要解决此问题,我只是排除了"arm64-v8a"文件夹.

在您的应用程序build.gradle内部和defaultConfig内部添加:

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

现在显示FILE_NAME.so的地方,将其替换为OpenCV"arm64-v8"文件夹中文件之一的文件名.根据需要多次添加排除行,以排除arm64-v8文件夹内的所有文件.

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.

解决方案

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.

这篇关于带有Tesseract和OpenCV的Android UnsatisfiedLinkError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆