0

I am facing problem with opencv in android. I tried a lot searching in google and also try to debug .But not able to figure out the solution. Here is hte logcat file:

06-27 16:52:41.423: E/AndroidRuntime(6974): FATAL EXCEPTION: main
06-27 16:52:41.423: E/AndroidRuntime(6974): java.lang.UnsatisfiedLinkError: Couldn't load native_sample: findLibrary returned null
06-27 16:52:41.423: E/AndroidRuntime(6974):     at java.lang.Runtime.loadLibrary(Runtime.java:365)
06-27 16:52:41.423: E/AndroidRuntime(6974):     at java.lang.System.loadLibrary(System.java:535)
06-27 16:52:41.423: E/AndroidRuntime(6974):     at org.opencv.face.Sample3Native$1.onManagerConnected(Sample3Native.java:83)
06-27 16:52:41.423: E/AndroidRuntime(6974):     at org.opencv.android.AsyncServiceHelper$1.onServiceConnected(AsyncServiceHelper.java:314)
06-27 16:52:41.423: E/AndroidRuntime(6974):     at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1068)
06-27 16:52:41.423: E/AndroidRuntime(6974):     at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1085)
06-27 16:52:41.423: E/AndroidRuntime(6974):     at android.os.Handler.handleCallback(Handler.java:605)
06-27 16:52:41.423: E/AndroidRuntime(6974):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-27 16:52:41.423: E/AndroidRuntime(6974):     at android.os.Looper.loop(Looper.java:137)
06-27 16:52:41.423: E/AndroidRuntime(6974):     at android.app.ActivityThread.main(ActivityThread.java:4441)
06-27 16:52:41.423: E/AndroidRuntime(6974):     at java.lang.reflect.Method.invokeNative(Native Method)
06-27 16:52:41.423: E/AndroidRuntime(6974):     at java.lang.reflect.Method.invoke(Method.java:511)
06-27 16:52:41.423: E/AndroidRuntime(6974):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
06-27 16:52:41.423: E/AndroidRuntime(6974):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
06-27 16:52:41.423: E/AndroidRuntime(6974):     at dalvik.system.NativeStart.main(Native Method)

I can say that the problem is in loading the native_sample library. But don't have any solution. I am getting error in the following line:

// Load native library after(!) OpenCV initialization
System.loadLibrary("native_sample");

Here is my android.mk file :

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

include ../../sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := native_sample
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_LDLIBS +=  -llog -ldl

include $(BUILD_SHARED_LIBRARY)

And here is my application.mk file:

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi

Here is my console output:

**** Build of configuration Default for project Face Recognition_opencv ****

D:\NDK\android-ndk-r8e-windows-x86\android-ndk-r8e\ndk-build.cmd 
"Compile++ thumb : native_sample <= jni_part.cpp
SharedLibrary  : libnative_sample.so
Install        : libnative_sample.so => libs/armeabi/libnative_sample.so

**** Build Finished ****

And my bin file is not generating. That's i am getting error in "setContentView(R.layout.activity_main);" here in "R" .

Developer
  • 385
  • 1
  • 3
  • 18
  • 1
    Are you sure that your library is compiled successfully? Can you show your `Android.mk` file? – JonasVautherin Jun 27 '13 at 12:04
  • I have added the android.mk file. – Developer Jun 27 '13 at 16:31
  • And are you sure that your C++ code compiled successfully? You can try to build it manually using the command `ndk-build` or build the C++ part using Eclipse. – JonasVautherin Jun 28 '13 at 07:34
  • From where i can know that c++ code compiled successfull? – Developer Jun 30 '13 at 19:35
  • In Eclipse, click on "Build" and have a look at the output in the console... – JonasVautherin Jun 30 '13 at 21:29
  • I am getting this in my console: D:\NDK\android-ndk-r8e-windows-x86\android-ndk-r8e\ndk-build.cmd jni/Android.mk:7: ../../sdk/native/jni/OpenCV.mk: No such file or directory make: *** No rule to make target `../../sdk/native/jni/OpenCV.mk'. Stop. **** Build Finished **** – Developer Jul 01 '13 at 11:31
  • That's your error: your C++ code is never compiled, which explains the `UnsatisfiedLinkError`. Edit the question to add this. – JonasVautherin Jul 01 '13 at 13:50
  • But got another error . It is memory leak error. – Developer Jul 02 '13 at 09:22
  • Then you should close this question, validate the answer (if it is correct) and create another question. Try to be clearer this time, and write the output of the console in the question directly! – JonasVautherin Jul 02 '13 at 15:51

1 Answers1

1

In your Android.mk file, there should be an include looking like:

include $(LOCAL_PATH)/../../sdk/native/jni/OpenCV.mk

You need to change it to point to your actual OpenCV.mk file (i.e. $(LOCAL_PATH) is the path to your jni folder, and you need to point to <your OpenCV4Android folder>/sdk/native/jni/OpenCV.mk).

JonasVautherin
  • 7,297
  • 6
  • 49
  • 95