[英]Android UnsatisfiedLinkError With Tesseract and OpenCV
I have been trying to get OpenCV and the android version of tesseract (tess-two) to work with my android app.我一直在尝试让 OpenCV 和 tesseract (tess-two) 的 android 版本与我的 android 应用程序一起使用。 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.我正在 Android Studio 1.4 中开发,问题是如果我单独添加 tess-two 依赖项,应用程序运行良好,我可以很好地加载 tess-two 库。 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:接下来,当我将 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)
Once I remove the OpenCV libraries and dependency from the app, tess-two begins to work again.从应用程序中删除 OpenCV 库和依赖项后,tess-two 再次开始工作。
Here is my OpenCV build.gradle :这是我的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 :这是我的 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另外这里是我的项目结构的图片,每个库都被圈起来,它们各自的 libs 文件夹也被圈起来(包含 .so 文件):项目结构
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. OpenCV 库在本机 libs 文件夹中有一个名为“arm64-v8a”的文件夹,而 tess-two 库不包含这样的文件夹。 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.这是一个问题,因为当没有可用于 tesseract for android (tess-two) 的 64 位库时,“arm64-v8a”文件夹将使应用程序以 64 位模式运行,从而引发问题中显示的崩溃。
To fix this, I simply excluded the "arm64-v8a" folder.为了解决这个问题,我只是排除了“arm64-v8a”文件夹。
Inside your app build.gradle and inside defaultConfig add:在您的应用 build.gradle 和 defaultConfig 中添加:
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.现在它说 FILE_NAME.so,用你的 OpenCV“arm64-v8”文件夹中的文件之一的文件名替换它。 Add the exclude line as many times as required to exclude all files inside the arm64-v8 folder.根据需要多次添加 exclude 行以排除 arm64-v8 文件夹中的所有文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.