简体   繁体   English

Android的原生OpenCV示例抛出UnsatisfiedLinkError

[英]Native OpenCV Samples for Android throws UnsatisfiedLinkError

I try to run the opencv android samples on the emulator. 我尝试在模拟器上运行opencv android示例。 The samples with native code eg sample "Tutorial 2 Advanced - 1. Add Native OpenCV" fails. 具有本机代码的示例例如样本“Tutorial 2 Advanced - 1. Add Native OpenCV”失败。 I have a Win7 x86 System. 我有一个Win7 x86系统。 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 谢谢

Change the line 改变线

APP_ABI := armeabi-v7a

in jni/Application.mk to jni/Application.mk

APP_ABI := armeabi

By default OpenCV samples are configured for modern armv7-a hardware. 默认情况下,OpenCV示例配置为现代armv7-a硬件。

Really nice answer by Andrey Kamaev! 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: 如果你知道你的硬件细节(对于你的情况是它的x86)..你可以定义如下:

APP_ABI := x86 APP_ABI:= x86

We can also define in jni/Application.mk as following: 我们还可以在jni / Application.mk中定义如下:

APP_ABI := armeabi armeabi-v7a x86 APP_ABI:= armeabi armeabi-v7a x86

Now when we build the application, there are 3 shared object library file will be created. 现在,当我们构建应用程序时,将创建3个共享对象库文件。 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). 当我在平板电脑中运行示例OpenCV Android原生应用程序时(作为其硬件支持armeabi-v7a),它工作正常,但同样的应用程序无法在我的三星Galaxy ACE移动设备上运行(没有armeabi-v7a支持)。

So, I set APP_ABI := armeabi armeabi-v7a and now the app runs nicely in both Tablet and Handset :) 所以,我设置APP_ABI:= armeabi armeabi-v7a,现在应用程序在平板电脑和手机中运行良好:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM