适用于 Android 的本机 OpenCV 示例抛出 UnsatisfiedLinkError

发布于 2024-12-08 08:09:46 字数 3204 浏览 0 评论 0原文

我尝试在模拟器上运行 opencv android 示例。具有本机代码的示例(例如示例“教程 2 高级 - 1. 添加本机 OpenCV”)失败。我有一个Win7 x86系统。我可以构建本机库,但如果运行示例,我总是会遇到以下异常:

 
10-04 08:08:19.179: WARN/dalvikvm(696): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/opencv/samples/tutorial3/Sample3View;
10-04 08:08:19.190: DEBUG/AndroidRuntime(696): Shutting down VM
10-04 08:08:19.190: WARN/dalvikvm(696): threadid=1: thread exiting with uncaught exception (group=0x40015560)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): FATAL EXCEPTION: main
10-04 08:08:19.289: ERROR/AndroidRuntime(696): java.lang.ExceptionInInitializerError
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at org.opencv.samples.tutorial3.Sample3Native.onCreate(Sample3Native.java:23)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.os.Looper.loop(Looper.java:123)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.app.ActivityThread.main(ActivityThread.java:3683)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at java.lang.reflect.Method.invokeNative(Native Method)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at java.lang.reflect.Method.invoke(Method.java:507)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at dalvik.system.NativeStart.main(Native Method)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load native_sample: findLibrary returned null
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at java.lang.Runtime.loadLibrary(Runtime.java:429)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at java.lang.System.loadLibrary(System.java:554)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at org.opencv.samples.tutorial3.Sample3View.(Sample3View.java:27)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     ... 14 more
10-04 08:08:19.389: WARN/ActivityManager(70):   Force finishing activity org.opencv.samples.tutorial3/.Sample3Native
10-04 08:08:19.959: WARN/ActivityManager(70): Activity pause timeout for HistoryRecord{406f26a0 org.opencv.samples.tutorial3/.Sample3Native}
10-04 08:08:20.089: DEBUG/dalvikvm(70): GC_EXPLICIT freed 92K, 47% free 4404K/8263K, external 5449K/5830K, paused 103ms

有什么想法,如何解决这个问题? 谢谢

I try to run the opencv android samples on the emulator. The samples with native code e.g. sample "Tutorial 2 Advanced - 1. Add Native OpenCV" fails. I have a Win7 x86 System. I can build the native libs but i always get the following exception if i run the sample:

 
10-04 08:08:19.179: WARN/dalvikvm(696): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/opencv/samples/tutorial3/Sample3View;
10-04 08:08:19.190: DEBUG/AndroidRuntime(696): Shutting down VM
10-04 08:08:19.190: WARN/dalvikvm(696): threadid=1: thread exiting with uncaught exception (group=0x40015560)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): FATAL EXCEPTION: main
10-04 08:08:19.289: ERROR/AndroidRuntime(696): java.lang.ExceptionInInitializerError
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at org.opencv.samples.tutorial3.Sample3Native.onCreate(Sample3Native.java:23)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.os.Looper.loop(Looper.java:123)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at android.app.ActivityThread.main(ActivityThread.java:3683)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at java.lang.reflect.Method.invokeNative(Native Method)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at java.lang.reflect.Method.invoke(Method.java:507)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at dalvik.system.NativeStart.main(Native Method)
10-04 08:08:19.289: ERROR/AndroidRuntime(696): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load native_sample: findLibrary returned null
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at java.lang.Runtime.loadLibrary(Runtime.java:429)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at java.lang.System.loadLibrary(System.java:554)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     at org.opencv.samples.tutorial3.Sample3View.(Sample3View.java:27)
10-04 08:08:19.289: ERROR/AndroidRuntime(696):     ... 14 more
10-04 08:08:19.389: WARN/ActivityManager(70):   Force finishing activity org.opencv.samples.tutorial3/.Sample3Native
10-04 08:08:19.959: WARN/ActivityManager(70): Activity pause timeout for HistoryRecord{406f26a0 org.opencv.samples.tutorial3/.Sample3Native}
10-04 08:08:20.089: DEBUG/dalvikvm(70): GC_EXPLICIT freed 92K, 47% free 4404K/8263K, external 5449K/5830K, paused 103ms

Any ideas, how to fix this problem?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

随遇而安 2024-12-15 08:09:46

行更改

APP_ABI := armeabi-v7a

jni/Application.mk 中的

APP_ABI := armeabi

为“默认情况下,OpenCV 示例是针对现代 armv7-a 硬件配置的”。

Change the line

APP_ABI := armeabi-v7a

in jni/Application.mk to

APP_ABI := armeabi

By default OpenCV samples are configured for modern armv7-a hardware.

淡莣 2024-12-15 08:09:46

安德烈·卡马耶夫的回答非常好!

以下是我刚刚从我的经验中学到的:

如果您知道您的硬件详细信息(对于您的情况是 x86)..您可以定义如下:

APP_ABI := x86

我们还可以在 jni/Application.mk 中定义如下:

APP_ABI := armeabi armeabi-v7a x86

现在,当我们构建应用程序时,将创建 3 个共享对象库文件。然后当我们运行应用程序时,基于目标设备的相应库将被加载。

当我在平板电脑中运行示例 OpenCV Android 本机应用程序(因为其硬件支持armeabi-v7a)时,它工作正常,但相同的应用程序无法在我的三星 Galaxy ACE 手机上运行(不支持armeabi-v7a)。

因此,我设置了 APP_ABI := armeabi armeabi-v7a,现在该应用程序在平板电脑和手机上都运行良好:)

Really nice answer by Andrey Kamaev!

Following is what I just learned from my experience:

If you know your hardware details (for your case its x86).. you can define as following:

APP_ABI := x86

We can also define in jni/Application.mk as following:

APP_ABI := armeabi armeabi-v7a x86

Now when we build the application, there are 3 shared object library file will be created. Then when we run the application, based on target device corresponding library will be loaded.

When I run sample OpenCV Android native app in Tablet (as its hardware support armeabi-v7a), it worked fine but same app failed to run at my Samsung Galaxy ACE mobile (does not have armeabi-v7a support).

So, I set APP_ABI := armeabi armeabi-v7a and now the app runs nicely in both Tablet and Handset :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文