Ask Your Question

Revision history [back]

Can not run OpenCV samples with native C++ code

Hello,

I'm a newbie in Android developing and it's the first time I use OpenCV. Following OpenCV guide, I managed to run 6 of the 9 applications. The remaining 3 are the one with native C++ code: "Face_detection", "Native_activity" and "mixed_processing". I added the NDK path, at first I added a environment variable NDKROOT, but finally I put the full path.

image description

The Android target is 4.4w (API20)

When I run the application, the message written in the console was:

02:43:08 * Auto Build of configuration Default for project OpenCV Sample - native-activity * "C:\Works\android-ndk-r9d\ndk-build.cmd" Android NDK: WARNING:jni/Android.mk:native_activity: non-system libraries in linker flags: -lopencv_java
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
[armeabi-v7a] Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi-v7a/gdbserver [armeabi-v7a] Gdbsetup : libs/armeabi-v7a/gdb.setup [armeabi-v7a] Install : libnative_activity.so => libs/armeabi-v7a/libnative_activity.so

And those are the errors in the LogCat:

07-27 02:43:18.497: E/dalvikvm(2439): dlopen("/data/app-lib/org.opencv.samples.NativeActivity-2/libnative_activity.so") failed: Cannot load library: load_library(linker.cpp:761): not a valid ELF executable: /data/app-lib/org.opencv.samples.NativeActivity-2/libnative_activity.so 07-27 02:43:18.497: D/AndroidRuntime(2439): Shutting down VM 07-27 02:43:18.497: W/dalvikvm(2439): threadid=1: thread exiting with uncaught exception (group=0xa6186908) 07-27 02:43:18.497: E/AndroidRuntime(2439): FATAL EXCEPTION: main 07-27 02:43:18.497: E/AndroidRuntime(2439): java.lang.UnsatisfiedLinkError: Cannot load library: load_library(linker.cpp:761): not a valid ELF executable: /data/app-lib/org.opencv.samples.NativeActivity-2/libnative_activity.so 07-27 02:43:18.497: E/AndroidRuntime(2439): at java.lang.Runtime.loadLibrary(Runtime.java:371) 07-27 02:43:18.497: E/AndroidRuntime(2439): at java.lang.System.loadLibrary(System.java:535) 07-27 02:43:18.497: E/AndroidRuntime(2439): at org.opencv.samples.NativeActivity.CvNativeActivity$1.onManagerConnected(CvNativeActivity.java:21) 07-27 02:43:18.497: E/AndroidRuntime(2439): at org.opencv.android.AsyncServiceHelper$1.onServiceConnected(AsyncServiceHelper.java:318) 07-27 02:43:18.497: E/AndroidRuntime(2439): at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1101) 07-27 02:43:18.497: E/AndroidRuntime(2439): at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1118) 07-27 02:43:18.497: E/AndroidRuntime(2439): at android.os.Handler.handleCallback(Handler.java:725) 07-27 02:43:18.497: E/AndroidRuntime(2439): at android.os.Handler.dispatchMessage(Handler.java:92) 07-27 02:43:18.497: E/AndroidRuntime(2439): at android.os.Looper.loop(Looper.java:137) 07-27 02:43:18.497: E/AndroidRuntime(2439): at android.app.ActivityThread.main(ActivityThread.java:5041) 07-27 02:43:18.497: E/AndroidRuntime(2439): at java.lang.reflect.Method.invokeNative(Native Method) 07-27 02:43:18.497: E/AndroidRuntime(2439): at java.lang.reflect.Method.invoke(Method.java:511) 07-27 02:43:18.497: E/AndroidRuntime(2439): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 07-27 02:43:18.497: E/AndroidRuntime(2439): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 07-27 02:43:18.497: E/AndroidRuntime(2439): at dalvik.system.NativeStart.main(Native Method)

One last thing when I opened The two files "DetectionBasedTracker_jni.ccp" and "DetectionBasedTracker_jni.h" from "Face_detection" application, errors were shown and I couldn't run the project anymore.

in DetectionBasedTracker_jni.h: "Type JNICALL could not be resolved" some thing for "JNIEnv", "jclass", "jstring" and "jint".

in DetectionBasedTracker_jni.ccp: the some error is shown many time as for: function __android_log_print, symboles: "ANDROID_LOG_DEBUG", "std", "Vector"...

If anything is unclear please tell me, you're help is so precious for me.

Thanks a lot a have a nice day. :)

Rym.^^

click to hide/show revision 2
retagged

updated 2014-07-27 00:33:53 -0600

berak gravatar image

Can not run OpenCV samples with native C++ code

Hello,

I'm a newbie in Android developing and it's the first time I use OpenCV. Following OpenCV guide, I managed to run 6 of the 9 applications. The remaining 3 are the one with native C++ code: "Face_detection", "Native_activity" and "mixed_processing". I added the NDK path, at first I added a environment variable NDKROOT, but finally I put the full path.

image description

The Android target is 4.4w (API20)

When I run the application, the message written in the console was:

02:43:08 * Auto Build of configuration Default for project OpenCV Sample - native-activity * "C:\Works\android-ndk-r9d\ndk-build.cmd" Android NDK: WARNING:jni/Android.mk:native_activity: non-system libraries in linker flags: -lopencv_java
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
[armeabi-v7a] Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi-v7a/gdbserver [armeabi-v7a] Gdbsetup : libs/armeabi-v7a/gdb.setup [armeabi-v7a] Install : libnative_activity.so => libs/armeabi-v7a/libnative_activity.so

And those are the errors in the LogCat:

07-27 02:43:18.497: E/dalvikvm(2439): dlopen("/data/app-lib/org.opencv.samples.NativeActivity-2/libnative_activity.so") failed: Cannot load library: load_library(linker.cpp:761): not a valid ELF executable: /data/app-lib/org.opencv.samples.NativeActivity-2/libnative_activity.so 07-27 02:43:18.497: D/AndroidRuntime(2439): Shutting down VM 07-27 02:43:18.497: W/dalvikvm(2439): threadid=1: thread exiting with uncaught exception (group=0xa6186908) 07-27 02:43:18.497: E/AndroidRuntime(2439): FATAL EXCEPTION: main 07-27 02:43:18.497: E/AndroidRuntime(2439): java.lang.UnsatisfiedLinkError: Cannot load library: load_library(linker.cpp:761): not a valid ELF executable: /data/app-lib/org.opencv.samples.NativeActivity-2/libnative_activity.so 07-27 02:43:18.497: E/AndroidRuntime(2439): at java.lang.Runtime.loadLibrary(Runtime.java:371) 07-27 02:43:18.497: E/AndroidRuntime(2439): at java.lang.System.loadLibrary(System.java:535) 07-27 02:43:18.497: E/AndroidRuntime(2439): at org.opencv.samples.NativeActivity.CvNativeActivity$1.onManagerConnected(CvNativeActivity.java:21) 07-27 02:43:18.497: E/AndroidRuntime(2439): at org.opencv.android.AsyncServiceHelper$1.onServiceConnected(AsyncServiceHelper.java:318) 07-27 02:43:18.497: E/AndroidRuntime(2439): at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1101) 07-27 02:43:18.497: E/AndroidRuntime(2439): at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1118) 07-27 02:43:18.497: E/AndroidRuntime(2439): at android.os.Handler.handleCallback(Handler.java:725) 07-27 02:43:18.497: E/AndroidRuntime(2439): at android.os.Handler.dispatchMessage(Handler.java:92) 07-27 02:43:18.497: E/AndroidRuntime(2439): at android.os.Looper.loop(Looper.java:137) 07-27 02:43:18.497: E/AndroidRuntime(2439): at android.app.ActivityThread.main(ActivityThread.java:5041) 07-27 02:43:18.497: E/AndroidRuntime(2439): at java.lang.reflect.Method.invokeNative(Native Method) 07-27 02:43:18.497: E/AndroidRuntime(2439): at java.lang.reflect.Method.invoke(Method.java:511) 07-27 02:43:18.497: E/AndroidRuntime(2439): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 07-27 02:43:18.497: E/AndroidRuntime(2439): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 07-27 02:43:18.497: E/AndroidRuntime(2439): at dalvik.system.NativeStart.main(Native Method)

One last thing when I opened The two files "DetectionBasedTracker_jni.ccp" and "DetectionBasedTracker_jni.h" from "Face_detection" application, errors were shown and I couldn't run the project anymore.

in DetectionBasedTracker_jni.h: "Type JNICALL could not be resolved" some thing for "JNIEnv", "jclass", "jstring" and "jint".

in DetectionBasedTracker_jni.ccp: the some error is shown many time as for: function __android_log_print, symboles: "ANDROID_LOG_DEBUG", "std", "Vector"...

If anything is unclear please tell me, you're help is so precious for me.

Thanks a lot a have a nice day. :)

Rym.^^