我在Android应用程序中通过JNI使用OpenCV。 libopencv_java.so太大了,大约7M。显然,我只需要几个库。 我检查OpenCV4Android中的libs,找出一些静态库,比如libopencv_core.a 这是我在Android.mk中的新代码,包含必要的OpenCV库。我包括libopencv_core.a,libopencv_highgui.a,libopencv_imgproc.a和一些第三方库,它们是:liblibjasper.a,liblibjpeg.a,liblibpng.a,liblibtiff.a
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_highgui_prebuilt
LOCAL_SRC_FILES := libopencv_highgui.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/OpenCV242AndroidSDKNativeJNI/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_imgproc_prebuilt
LOCAL_SRC_FILES := libopencv_imgproc.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/OpenCV242AndroidSDKNativeJNI/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libopencv_core_prebuilt
LOCAL_SRC_FILES := libopencv_core.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/OpenCV242AndroidSDKNativeJNI/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := liblibjpeg_prebuilt
LOCAL_SRC_FILES := liblibjpeg.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/OpenCV242AndroidSDKNativeJNI/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := liblibpng_prebuilt
LOCAL_SRC_FILES := liblibpng.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/OpenCV242AndroidSDKNativeJNI/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := liblibtiff_prebuilt
LOCAL_SRC_FILES := liblibtiff.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/OpenCV242AndroidSDKNativeJNI/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := liblibjasper_prebuilt
LOCAL_SRC_FILES := liblibjasper.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/OpenCV242AndroidSDKNativeJNI/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := native_jni
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_CFLAGS += -fpermissive
LOCAL_STATIC_LIBRARIES += libopencv_highgui_prebuilt
LOCAL_STATIC_LIBRARIES += libopencv_imgproc_prebuilt
LOCAL_STATIC_LIBRARIES += libopencv_core_prebuilt
LOCAL_STATIC_LIBRARIES += liblibjpeg_prebuilt
LOCAL_STATIC_LIBRARIES += liblibpng_prebuilt
LOCAL_STATIC_LIBRARIES += liblibtiff_prebuilt
LOCAL_STATIC_LIBRARIES += liblibjasper_prebuilt
LOCAL_LDLIBS += -llog -ldl
LOCAL_LDLIBS += -ljnigraphics
LOCAL_LDLIBS += -lz
include $(BUILD_SHARED_LIBRARY)
但它没有通过编译。一个长错误列表,都与断言失败有关:
/usr/src/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/ld: BFD (GNU Binutils) 2.21 assertion fail /usr/local/google/home/andrewhsieh/ndk-andrewhsieh/src/build/../binutils/binutils-2.21/bfd/elf32-arm.c:10190
Install : libnative_jni.so => libs/armeabi-v7a/libnative_jni.so
/usr/src/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/ld: BFD (GNU Binutils) 2.21 assertion fail /usr/local/google/home/andrewhsieh/ndk-andrewhsieh/src/build/../binutils/binutils-2.21/bfd/elf32-arm.c:10190
我也试图改变这些静态库的顺序;但它不起作用。 有什么建议吗?
答案 0 :(得分:0)
静态库链接只会引入您在代码中实际使用的功能,而不是.so
中的整个库。
查看OpenCV Android示例项目,了解如何使用静态链接。