Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Native OpenCV Samples for Android throws UnsatisfiedLinkError

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

like image 678
user978029 Avatar asked Dec 01 '22 01:12

user978029


2 Answers

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.

like image 100
Andrey Kamaev Avatar answered Dec 03 '22 15:12

Andrey Kamaev


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 :)

like image 23
Shekh Akther Avatar answered Dec 03 '22 14:12

Shekh Akther