3

I have downloaded the latest version of OpenCV4Android, the 2.4.5 version, and imported it into Eclipse Juno, after downloading all the right plugins.

All the tutorials work well on my Android emulator, except Native Activity. When I try to run it on my emulator, the application stops with this message: "OCV Native Activity has stopped unfortunately".

And my logcat is:

05-05 13:24:54.489: E/AndroidRuntime(884): FATAL EXCEPTION: main
05-05 13:24:54.489: E/AndroidRuntime(884): java.lang.UnsatisfiedLinkError: Couldn't load native_activity from loader dalvik.system.PathClassLoader[dexPath=/data/app/org.opencv.samples.NativeActivity-2.apk,libraryPath=/data/app-lib/org.opencv.samples.NativeActivity-2]: findLibrary returned null
05-05 13:24:54.489: E/AndroidRuntime(884):  at java.lang.Runtime.loadLibrary(Runtime.java:365)
05-05 13:24:54.489: E/AndroidRuntime(884):  at java.lang.System.loadLibrary(System.java:535)
05-05 13:24:54.489: E/AndroidRuntime(884):  at org.opencv.samples.NativeActivity.CvNativeActivity$1.onManagerConnected(CvNativeActivity.java:22)
05-05 13:24:54.489: E/AndroidRuntime(884):  at org.opencv.android.AsyncServiceHelper$1.onServiceConnected(AsyncServiceHelper.java:318)
05-05 13:24:54.489: E/AndroidRuntime(884):  at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1101)
05-05 13:24:54.489: E/AndroidRuntime(884):  at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1118)
05-05 13:24:54.489: E/AndroidRuntime(884):  at android.os.Handler.handleCallback(Handler.java:725)
05-05 13:24:54.489: E/AndroidRuntime(884):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-05 13:24:54.489: E/AndroidRuntime(884):  at android.os.Looper.loop(Looper.java:137)
05-05 13:24:54.489: E/AndroidRuntime(884):  at android.app.ActivityThread.main(ActivityThread.java:5041)
05-05 13:24:54.489: E/AndroidRuntime(884):  at java.lang.reflect.Method.invokeNative(Native Method)
05-05 13:24:54.489: E/AndroidRuntime(884):  at java.lang.reflect.Method.invoke(Method.java:511)
05-05 13:24:54.489: E/AndroidRuntime(884):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-05 13:24:54.489: E/AndroidRuntime(884):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-05 13:24:54.489: E/AndroidRuntime(884):  at dalvik.system.NativeStart.main(Native Method)

What can I do to fix this problem?

3 Answers3

0

The emulater can't find the Native Library

                        System.loadLibrary("native_activity");

You have to install first the apk from the openCV_sdk. the file is on samples

    example-native-activity.apk

Then you can play with the code on eclipse.

bob
  • 31
  • 4
  • I have installed the Native Activity first, and the application, if installed with "adb install" works fine. But, then, if I try to run the application from Eclipse, I have this result in the console:2013-05-05 16:51:47 - OpenCV Sample - native-activity] Re-installation failed due to different application signatures. [2013-05-05 16:51:47 - OpenCV Sample - native-activity] You must perform a full uninstall of the application. WARNING: This will remove the application data! [2013-05-05 16:51:47 -OpenCV Sample- native-activity] Please execute 'adb uninstall org.opencv.samples.NativeActivity' –  May 05 '13 at 14:53
  • I've also tried to add android native support by simply clicking on the project and selecting "add native support", but it doesn't show me the relative and correct .so file to add. Why? –  May 05 '13 at 16:56
0

You should first try to compile a lib. Simply enter the root of android project and execute

/home/user/android-ndk-r8b/ndk-build -C ./

other example

/home/user/android-ndk-r8b/ndk-build -C /home/user/opencv/OpenCV-2.4.5-android-sdk/samples/face-detection

This will build a lib in your folder eg.

/home/user/opencv/OpenCV-2.4.5-android-sdk/samples/face-detection/libs/armeabi-v7a/libdetection_based_tracker.so

Useful links: android_dev_intro , O4A_SDK & android

Girish Nair
  • 5,148
  • 5
  • 40
  • 61
Gelldur
  • 11,187
  • 7
  • 57
  • 68
0

This could be one of the reason where it fails:

CDT Builder is configured for Windows hosts, on Linux or MacOS ... remove ".cmd" and leave "${NDKROOT}/ndk-build". (go to Properties -> C/C++ Build -> Builder -> Build command and remove ".cmd", probably you might need to remove the open quote (") and close quote (") as well.)

Secondly check if the project contains libs/[architecture]/lib[module-name].so after build/auto-build.

morph85
  • 807
  • 10
  • 18