将第二个JNI库包含到我的Android项目(OpenCV)后出现错误 [英] Error after including a 2nd JNI library to my Android project (OpenCV)

查看:130
本文介绍了将第二个JNI库包含到我的Android项目(OpenCV)后出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将OpenCV添加到我现有的Android项目中,但是在合并它们时遇到了以下错误:

I'm trying to add OpenCV to an existing Android project of mine but while merging them I ran into the following error:

12-08 16:15:21.951 22052-22052/ai.inbi.face_recognition_robot E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                      Process: ai.inbi.wonderful_face_recognition_robot, PID: 22052
                                                                                      java.lang.UnsatisfiedLinkError: Couldn't load uvcNative from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/ai.inbi.wonderful_face_recognition_robot-1.apk"],nativeLibraryDirectories=[/data/app-lib/ai.inbi.wonderful_face_recognition_robot-1, /vendor/lib, /system/lib]]]: findLibrary returned null
                                                                                          at java.lang.Runtime.loadLibrary(Runtime.java:358)
                                                                                          at java.lang.System.loadLibrary(System.java:526)

我试图手动注释掉所有对OpenCV的引用,但是除非从我的libs文件夹中删除所有OpenCV文件,否则现有库(com.qihancloud.opensdk)找不到它自己的库函数. 我的库的文件夹结构是这样的:

I tried to manually comment out all references to OpenCV but unless I delete all OpenCV files from my libs folder the existing library (com.qihancloud.opensdk) fails to find it's own library functions. The folder structure of my libraries is like this:

如果在编译之前删除OpenCV库文件,一切正常. 另外,我的独立OpenCV项目正在运行,但是一旦我尝试将它们组合起来,它将无法执行.

If I remove the OpenCV library files before compiling everything works well. Also my standalone OpenCV project is working but as soon as I try to combine them it fails to execute.

我的应用程序build.gradle文件可以在这里看到: https://pastebin.com/Z7hPH3vy

My app build.gradle file can be seen here: https://pastebin.com/Z7hPH3vy

还有我的CMakeLists.txt https://pastebin.com/gGwgWtxP

And my CMakeLists.txt https://pastebin.com/gGwgWtxP

推荐答案

该错误表示文件 libuvcNative.so 尚未与APK一起安装.这可能是由多种根本原因引起的.

The error means that the file libuvcNative.so has not been installed with your APK. This can happen for a wild variety of root causes.

您的案例与此处所述的完全相同. QihanOpenSDK_1.1.8.0.aar 仅具有 libuvcNative.so armeabi 版本.解决方法是将 build.gradle 的第15行更改为

Your case is exactly same as described here. The QihanOpenSDK_1.1.8.0.aar only has an armeabi version of libuvcNative.so. The fix is to change line #15 of build.gradle to read

 abiFilters 'armeabi'

但是我必须承认,您的 CMakeLists.txt 使我感到困惑.对我来说

But I must confess that your CMakeLists.txt puzzled me. For me,

set_target_properties(lib_qihan PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR} /libs/QihanOpenSDK_1.1.8.0.aar)

不起作用.出于诚意,

set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR} /libs/${ANDROID_ABI}/libopencv_java3.so)

也与我的书不符.对于后者,我相信您只是在复制/粘贴脚本时添加了一个空格.

also does not match my books. For the latter, I believe that you simply added a space while copy/pasting the script.

对于前者,我知道一个特殊的技巧,可以从导入的 aar 用于本机版本.

For the former, I know a special trick to have an so file from an imported aar used in native build.

我相信您的工作版本不仅会丢弃所有OpenCV库,而且不会构建 libnative-lib.so .这样, cmake 不会寻找 libuvcNative.so ,但是由于 aar 已编译您的应用程序的依赖项.我想某些 QihanOpenSDK 类会明确调用

I believe that your working version not only discards all OpenCV libraries, but also does not build the libnative-lib.so. This way, cmake does never look for libuvcNative.so, but still this native lib is deployed with the APK because the aar is a compiled dependency of your app. I guess that some of the QihanOpenSDK classes explicitly calls

System.loadLibrary("uvcNative")

如果您的 libnative-lib.so 不使用来自 libuvcNative.so 的外部符号,则您不需要我上面提到的技巧,也不需要在您的 CMakeLists.txt 中完全提到 QihanOpenSDK .

If your libnative-lib.so does not use external symbols from libuvcNative.so, you don't need the trick I mentioned above and don't need to mention the QihanOpenSDK at all in your CMakeLists.txt.

这篇关于将第二个JNI库包含到我的Android项目(OpenCV)后出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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