java android静态初始化opencv 3.0无法加载库“opencv_java3”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33943699/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 22:19:53  来源:igfitidea点击:

android Static Initialization opencv 3.0 Cannot load library "opencv_java3"

javaandroidopencvandroid-ndk

提问by Garry Dunicazzz

Using Android ADTam trying to static initialize openCV so it included in the app build and users don't have to download openCV Manager from the Android playstore.

使用Android ADTam 尝试静态初始化 openCV,因此它包含在应用程序构建中,用户不必从 Android Playstore 下载 openCV Manager。

Am using openCV v3 (http://opencv.org/downloads.html)

我正在使用 openCV v3 ( http://opencv.org/downloads.html)

At the stage just trying to add static initialization to one of the samples in OpenCV-android-sdk\samples\face-detection.

在这个阶段只是尝试向 OpenCV-android-sdk\samples\face-detection 中的样本之一添加静态初始化。

I have followed the example (http://docs.opencv.org/2.4/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html)

我遵循了这个例子(http://docs.opencv.org/2.4/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html

Looked at lots of examples but as yet come up with no solution to getting it working. Very much hope someone might be able to help.

看了很多例子,但还没有想出让它工作的解决方案。非常希望有人能够提供帮助。

I did think might be due to libopencv_java3.so not being in the folder libs/armeabi-v7a/When i copy and paste it from OpenCV-android-sdk\sdk\native\libs\armeabi-v7ait disappears. I believe this could be something to do with the way the ndk is setup. Of course the issue could be something completely different.

我确实认为可能是由于 libopencv_java3.so 不在文件夹中libs/armeabi-v7a/当我从中复制并粘贴它时OpenCV-android-sdk\sdk\native\libs\armeabi-v7a它消失了。我相信这可能与 ndk 的设置方式有关。当然,问题可能完全不同。

LogCat gives this:

LogCat 给出了这个:

11-26 16:36:33.647: D/OpenCV/StaticHelper(13993): Trying to load library opencv_java3 
11-26 16:36:33.647: D/OpenCV/StaticHelper(13993): Cannot load library "opencv_java3" 
11-26 16:36:33.647: W/System.err(13993): java.lang.UnsatisfiedLinkError: Couldn't load opencv_java3 from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/org.opencv.samples.facedetect-1.apk"],nativeLibraryDirectories=[/data/app-lib/org.opencv.samples.facedetect-1, /vendor/lib, /system/lib, /vendor/lib]]]: findLibrary returned null 
11-26 16:36:33.767: D/OpenCV/StaticHelper(13993): Trying to load library opencv_java3 
11-26 16:36:33.767: D/OpenCV/StaticHelper(13993): Cannot load library "opencv_java3" 
11-26 16:36:33.767: W/System.err(13993): java.lang.UnsatisfiedLinkError: Couldn't load opencv_java3 from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/org.opencv.samples.facedetect-1.apk"],nativeLibraryDirectories=[/data/app-lib/org.opencv.samples.facedetect-1, /vendor/lib, /system/lib, /vendor/lib]]]: findLibrary returned null

回答by Thor_Bux

incase someone comes across this issue and uses AndroidStudio. You can fix it by simply copying the folder OpenCV-android-sdk\sdk\native\libs

以防有人遇到此问题并使用 AndroidStudio。您可以通过简单地复制文件夹 OpenCV-android-sdk\sdk\native\libs 来修复它

into your OpenCvProject/openCVLibrary310/source/main and rename it to jniLibs. So that the final structure looks like this: OpenCvProject/openCVLibrary310/source/main/jniLibs/ enter image description here

进入您的 OpenCvProject/openCVLibrary310/source/main 并将其重命名为 jniLibs。这样最终的结构看起来像这样:OpenCvProject/openCVLibrary310/source/main/jniLibs/ 在此处输入图片说明

If you already ran your project out of AndroidStudio make sure to delete it first from the device. Otherwise AndroidStudio might not redeploy it and because of that might not copy over the libs.

如果您已经在 AndroidStudio 中运行了您的项目,请确保先将其从设备中删除。否则 AndroidStudio 可能不会重新部署它,因此可能不会复制库。

It might also work if you copy the libs into your actual project and not into the openCVLibrary folder but I didn't try that.

如果您将库复制到实际项目而不是 openCVLibrary 文件夹中,它也可能起作用,但我没有尝试过。

回答by I L

Ensure you have the option to install modules set to "ON" before including Opencv.mk:

在包含 Opencv.mk 之前,确保您可以选择安装设置为“ON”的模块:

OPENCV_INSTALL_MODULES:=on
include ${OPENCV_ANDROID_SDK}/${ANDROID_SDK_JNI}/OpenCV.mk

I already set my variables in my makefile

我已经在我的 makefile 中设置了我的变量

see: http://docs.opencv.org/2.4/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html

见:http: //docs.opencv.org/2.4/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html

回答by Hans Araya

I fought with this problem for hours, when I tried something just for fun and VOILá! I got the problem on System.loadLibrary("whateverYourLibraryWasCalled");so I add loaded OpenCV just before:

我与这个问题斗争了几个小时,当时我只是为了好玩而尝试一些东西,瞧!我遇到了问题,System.loadLibrary("whateverYourLibraryWasCalled");所以我在之前添加了加载的 OpenCV:

static {
    System.loadLibrary("opencv_java3");
    System.loadLibrary("MyOpencvLibs");
}

And everything worked just fine.

一切都很好。

回答by u10538282

I meet with this question recently! Because I don‘t put the so into the folder "app/src/main/jniLibs" but to the folder "app/src/main/cpp/libs"(custom)

我最近遇到这个问题!因为我没有将 so 放入文件夹“app/src/main/jniLibs”而是放入文件夹“app/src/main/cpp/libs”(自定义)

Folder path:

文件夹路径:

folder path

文件夹路径

Runtime error:

运行时错误:

runtime error

运行时错误

APK content:

APK内容:

apk content

apk 内容

we can see, libopencv_java3.sonot packed to apk file.

我们可以看到,libopencv_java3.so没有打包成apk文件。

I modified 'so' folder path to "app/src/main/jniLibs" and modified "CMakeLists.txt".

我将“so”文件夹路径修改为“app/src/main/jniLibs”并修改了“CMakeLists.txt”。

Use jniLibs:

使用 jniLibs:

use jniLibs

使用 jniLibs

and build project.

并构建项目。

we can see.

我们可以看到。

apk content

apk 内容

we can find libopencv_java3.so.

我们可以找到libopencv_java3.so

and app run normally.

和应用程序正常运行。

so I think we should put all 'so' files to jniLibs folder.

所以我认为我们应该把所有的“so”文件放到 jniLibs 文件夹中。

If you want to use other folder. you should config in your "build.gradle"

如果要使用其他文件夹。你应该在你的“build.gradle”中配置