简体   繁体   中英

Could Not Load Library libopencv_java.so

I'm currently facing a certain native compilation issue. Just to be clear, I have done my opencv-ndk configuration with no error. In fact, I have compiled and executed a few samples and tutorials from the source. However, when I try to compile this, it gives me an error indicate I have lost something in my library. Below is the log file from eclipse. Notice, insides the eclipse project, I do have libopencv_java.so under obj->local->armeabi-v7a->objs directory.

03-19 10:14:11.142: D/dalvikvm(6360): Trying to load lib /data/app-lib/com.example.detectimage-2/libnative_sample.so 0x4141bc60
03-19 10:14:11.152: E/dalvikvm(6360): dlopen("/data/app-lib/com.example.detectimage-2/libnative_sample.so") failed: Cannot load library: soinfo_link_image(linker.cpp:1635): could not load library "libopencv_java.so" needed by "libnative_sample.so"; caused by load_library(linker.cpp:745): library "libopencv_java.so" not found
03-19 10:14:11.152: E/JNI(6360): WARNING: Could not load libmysharedlibrary.so
03-19 10:14:11.152: I/Sample::Activity(6360): Instantiated new class com.example.detectimage.DetectImageActivity
03-19 10:14:11.162: I/Sample::Activity(6360): onCreate
03-19 10:14:11.162: D/dalvikvm(6360): Trying to load lib /data/app-lib/com.example.detectimage-2/libnative_sample.so 0x4141bc60
03-19 10:14:11.162: E/dalvikvm(6360): dlopen("/data/app-lib/com.example.detectimage-2/libnative_sample.so") failed: Cannot load library: find_library(linker.cpp:889): "/data/app-lib/com.example.detectimage-2/libnative_sample.so" failed to load previously
03-19 10:14:11.162: W/dalvikvm(6360): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/example/detectimage/CameraPreview;
03-19 10:14:11.172: D/AndroidRuntime(6360): Shutting down VM
03-19 10:14:11.172: W/dalvikvm(6360): threadid=1: thread exiting with uncaught exception (group=0x40f06ae0)
03-19 10:14:11.182: E/AndroidRuntime(6360): FATAL EXCEPTION: main

In case you need my Android.mk file as well

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
OPENCV_INSTALL_MODULES:=on
OPENCV_CAMERA_MODULES:=off
include D:\Development\OpenCV-2.4.8-android-sdk\sdk\native\jni\OpenCV.mk

LOCAL_C_INCLUDES:= D:\Development\OpenCV-2.4.8-android-sdk\sdk\native\jni\include
LOCAL_MODULE    := native_sample
LOCAL_CFLAGS    := -Werror -O3 -ffast-math
LOCAL_LDLIBS    += -llog


LOCAL_SRC_FILES := jni_part.cpp
include $(BUILD_SHARED_LIBRARY)

Frankly, I have searched the entire resources, and have tried plenty of them, it just couldn't work. Perhaps I am new to this topic, certain advanced solution I wasn't able to follow to. I wish I could get some better understanding here.Your help is so appreciated.

Looks like this is a runtime error and that you're able to build your native code without problems. In order to include any necessary .so files in your .apk, you need to make them available in the lib/ subdirectory of the project yo want to deploy.

This can be as simple as copying them over manually, but ant should be smart enough to copy it over for you. If it's not doing so, there's probably something else going on.

Another alternative is to link statically to OpenCV. You can do this by adding this line before including OpenCV.mk in your own Android.mk:

OPENCV_LIB_TYPE :=STATIC

This, of course, only make sense, if you're OpenCV build comes with static libraries (lib*.a). You'll notice that by linking statically to OpenCV, your .so file will increase slightly in file size, but there won't be any need to package the libopencv_java.so anymore. Your .so has everything it needs from OpenCV.

To sum up, if your project uses any .so files, have them under /lib when the .apk gets packaged so that your application can find them at launch-/runtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM