我在android中面临opencv的问题。我在谷歌尝试了很多搜索并尝试调试。但是无法找出解决方案。这是hte logcat文件:
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)
我可以说问题在于加载native_sample库。但是没有任何解决方案。我在以下行中收到错误:
// Load native library after(!) OpenCV initialization
System.loadLibrary("native_sample");
这是我的android.mk文件:
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)
这是我的application.mk文件:
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi
这是我的控制台输出:
**** 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 ****
我的bin文件没有生成。那是我在“{”中的"setContentView(R.layout.activity_main);"
错误。
答案 0 :(得分:1)
在Android.mk
文件中,应该有include
看起来像:
include $(LOCAL_PATH)/../../sdk/native/jni/OpenCV.mk
您需要将其更改为指向实际的OpenCV.mk
文件(即$(LOCAL_PATH)
是jni
文件夹的路径,您需要指向<your OpenCV4Android folder>/sdk/native/jni/OpenCV.mk
)