NDK-build不会创建.so文件

时间:2015-12-08 09:21:32

标签: android android-ndk

我正在尝试构建一个名为receiptrecognizer的本机库,该库是从Android应用程序调用的。

我认为我正确设置了一切,因为NDK-build没有显示任何错误。但是,当我致电System.loadLibrary("receiptrecognizer");时,我会收到UnsatisfiedLinkError

原因是没有libreceiptrecognizer.so文件 在apk内。实际上没有libreceiptrecognizer.so文件 在我运行ndk-build时随处创建。

为什么没有生成.so文件?

receiptrecognizer使用openCV和tesseract(后者使用leptonica)。

这是我的Android.mk:

    LOCAL_PATH := $(call my-dir)

    include $(CLEAR_VARS)
    OPENCV_CAMERA_MODULES:=on
    OPENCV_INSTALL_MODULES:=on
    OPENCV_LIB_TYPE:=SHARED
    include ../opencv4android/sdk/native/jni/OpenCV.mk

    include $(CLEAR_VARS)
    LOCAL_MODULE := lept
    LOCAL_SRC_FILES := ../../tess-two/libs/$(TARGET_ARCH_ABI)/liblept.so
    include $(PREBUILT_SHARED_LIBRARY)

    include $(CLEAR_VARS)
    LOCAL_MODULE := tess
    LOCAL_SRC_FILES := ../../tess-two/libs/$(TARGET_ARCH_ABI)/libtess.so
    include $(PREBUILT_SHARED_LIBRARY)


    LOCAL_MODULE    := receiptrecognizer

    LOCAL_SRC_FILES := \
        src/OCRImagePreprocessor.cpp \
        src/util.cpp \
        ocrimagepreprocessorjni.cpp

    LOCAL_C_INCLUDES := \
      $(LOCAL_PATH)/../../opencv4android/sdk/native/jni/include \
      $(LOCAL_PATH)/../../tess-two/jni/com_googlecode_leptonica_android/src/src \
      $(LOCAL_PATH)/../../tess-two/jni/com_googlecode_tesseract_android/src \
      $(LOCAL_PATH)/../../tess-two/jni/com_googlecode_tesseract_android/src/ccutil \
      $(LOCAL_PATH)/../../tess-two/jni/com_googlecode_tesseract_android/src/ccstruct \
      $(LOCAL_PATH)/../../tess-two/jni/com_googlecode_tesseract_android/src/ccmain \
      $(LOCAL_PATH)/jni/src \
      $(LOCAL_PATH)/jni \
      $(LOCAL_PATH)/src \
      $(LOCAL_PATH)

    LOCAL_CFLAGS := \
      --std=c++11

    LOCAL_SHARED_LIBRARIES := \
        opencv_java3 \
        lept \
        tess

    include $(BUILD_SHARED_LIBRARY)

这是ndk-build的输出(除了对目标的覆盖命令的一些警告):

[armeabi] Prebuilt       : liblept.so <= jni/../../tess-two/libs/armeabi/
[armeabi] Install        : liblept.so => libs/armeabi/liblept.so
[armeabi] Prebuilt       : libopencv_java3.so <= ../opencv4android/sdk/native/jni/../libs/armeabi/
[armeabi] Install        : libopencv_java3.so => libs/armeabi/libopencv_java3.so
[armeabi] Compile++ thumb: receiptrecognizer <= OCRImagePreprocessor.cpp
[armeabi] Compile++ thumb: receiptrecognizer <= util.cpp
[armeabi] Compile++ thumb: receiptrecognizer <= ocrimagepreprocessorjni.cpp
make.exe: Circular obj/local/armeabi/libtess.so <- obj/local/armeabi/libtess.so dependency dropped.
[armeabi] Prebuilt       : libtess.so <= obj/local/armeabi/objs/receiptrecognizer/src/
[armeabi] Install        : libtess.so => libs/armeabi/libtess.so
[armeabi-v7a] Prebuilt       : liblept.so <= jni/../../tess-two/libs/armeabi-v7a/
[armeabi-v7a] Install        : liblept.so => libs/armeabi-v7a/liblept.so
[armeabi-v7a] Prebuilt       : libopencv_java3.so <= ../opencv4android/sdk/native/jni/../libs/armeabi-v7a/
[armeabi-v7a] Install        : libopencv_java3.so => libs/armeabi-v7a/libopencv_java3.so
[armeabi-v7a] Compile++ thumb: receiptrecognizer <= OCRImagePreprocessor.cpp
[armeabi-v7a] Compile++ thumb: receiptrecognizer <= util.cpp
[armeabi-v7a] Compile++ thumb: receiptrecognizer <= ocrimagepreprocessorjni.cpp
make.exe: Circular obj/local/armeabi-v7a/libtess.so <- obj/local/armeabi-v7a/libtess.so dependency dropped.
[armeabi-v7a] Prebuilt       : libtess.so <= obj/local/armeabi-v7a/objs/receiptrecognizer/src/
[armeabi-v7a] Install        : libtess.so => libs/armeabi-v7a/libtess.so
[x86] Prebuilt       : liblept.so <= jni/../../tess-two/libs/x86/
[x86] Install        : liblept.so => libs/x86/liblept.so
[x86] Prebuilt       : libopencv_java3.so <= ../opencv4android/sdk/native/jni/../libs/x86/
[x86] Install        : libopencv_java3.so => libs/x86/libopencv_java3.so
[x86] Compile++      : receiptrecognizer <= OCRImagePreprocessor.cpp
[x86] Compile++      : receiptrecognizer <= util.cpp
[x86] Compile++      : receiptrecognizer <= ocrimagepreprocessorjni.cpp
make.exe: Circular obj/local/x86/libtess.so <- obj/local/x86/libtess.so dependency dropped.
[x86] Prebuilt       : libtess.so <= obj/local/x86/objs/receiptrecognizer/src/
[x86] Install        : libtess.so => libs/x86/libtess.so
[mips] Prebuilt       : liblept.so <= jni/../../tess-two/libs/mips/
[mips] Install        : liblept.so => libs/mips/liblept.so
[mips] Prebuilt       : libopencv_java3.so <= ../opencv4android/sdk/native/jni/../libs/mips/
[mips] Install        : libopencv_java3.so => libs/mips/libopencv_java3.so
[mips] Compile++      : receiptrecognizer <= OCRImagePreprocessor.cpp
[mips] Compile++      : receiptrecognizer <= util.cpp
[mips] Compile++      : receiptrecognizer <= ocrimagepreprocessorjni.cpp
make.exe: Circular obj/local/mips/libtess.so <- obj/local/mips/libtess.so dependency dropped.
[mips] Prebuilt       : libtess.so <= obj/local/mips/objs/receiptrecognizer/src/
[mips] Install        : libtess.so => libs/mips/libtess.so

任何想法都表示赞赏。

1 个答案:

答案 0 :(得分:1)

在您显示的ndk-build的跟踪中,我看到此行make.exe: Circular obj/local/mips/libtess.so <- obj/local/mips/libtess.so dependency dropped.

我认为这就是为什么你没有生成正确的.so lib。我想你忘记在include $(CLEAR_VARS)之前添加LOCAL_MODULE := receiptrecognizer

我希望这对你有用。