2017-07-28 164 views
1

我是一个android开发人员,但我是新的Android NDK,请帮助,或告诉我你还需要什么/你将如何尝试解决这种类型的问题。编译dlib和opencv与android ndk

我用this dlib为android例子和官方opencv for android library,我想将两者集成到一个应用程序中。当我试图建立的项目,我得到以下错误:

FAILURE: Build failed with an exception. 

* What went wrong: 
Execution failed for task ':openCVSamplefacedetection:externalNativeBuildDebug'. 
> Build command failed. 
    Error while executing process /home/feli/Android/Sdk/ndk-bundle/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/home/feli/Development/android/test/face-detection/openCVSamplefacedetection/src/main/jni/Android.mk NDK_APPLICATION_MK=/home/feli/Development/android/test/face-detection/openCVSamplefacedetection/src/main/jni/Application.mk APP_ABI=mips64 NDK_ALL_ABIS=mips64 NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=/home/feli/Development/android/test/face-detection/openCVSamplefacedetection/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/home/feli/Development/android/test/face-detection/openCVSamplefacedetection/build/intermediates/ndkBuild/debug/lib /home/feli/Development/android/test/face-detection/openCVSamplefacedetection/build/intermediates/ndkBuild/debug/obj/local/mips64/libdetection_based_tracker.so} 
    [mips64] Compile++  : detection_based_tracker <= DetectionBasedTracker_jni.cpp 
    [mips64] Prebuilt  : libopencv_java3.so <= /home/feli/Android/openCV/OpenCV-android-sdk/sdk/native/jni/../libs/mips64/ 
    [mips64] SharedLibrary : libdetection_based_tracker.so 
    /home/feli/Development/android/test/face-detection/openCVSamplefacedetection/build/intermediates/ndkBuild/debug/obj/local/mips64/objs-debug/detection_based_tracker/DetectionBasedTracker_jni.o: In function `dlib_check_consistent_assert_usage': 
    /home/feli/Development/android/test/face-detection/openCVSamplefacedetection/src/main/jni/dlib/dlib/threads/threads_kernel_shared.h:44: undefined reference to `USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_' 
    clang++: error: linker command failed with exit code 1 (use -v to see invocation) 
    make: *** [/home/feli/Development/android/test/face-detection/openCVSamplefacedetection/build/intermediates/ndkBuild/debug/obj/local/mips64/libdetection_based_tracker.so] Error 1 


* Try: 
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. 

我的第一个猜测是,我的天堂/吨列入我Android.mk的source.cpp但placeing到src的文件并没有解决象征。 这里是我的Android.mk:

LOCAL_PATH := $(call my-dir) 

## Build dlib to static library 
include $(CLEAR_VARS) 
LOCAL_MODULE := dlib 
LOCAL_C_INCLUDES := $(LOCAL_PATH)/dlib 

LOCAL_SRC_FILES += \ 
       $(LOCAL_PATH)/dlib/dlib/all/source.cpp \ 
       $(LOCAL_PATH)/dlib//dlib/threads/threads_kernel_shared.cpp \ 
       $(LOCAL_PATH)/dlib/dlib/entropy_decoder/entropy_decoder_kernel_2.cpp \ 
       $(LOCAL_PATH)/dlib/dlib/base64/base64_kernel_1.cpp \ 
       $(LOCAL_PATH)/dlib/dlib/threads/threads_kernel_1.cpp \ 
       $(LOCAL_PATH)/dlib/dlib/threads/threads_kernel_2.cpp 

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES) 
include $(BUILD_STATIC_LIBRARY) 

# Build opencv 
include $(CLEAR_VARS) 
OPENCVROOT := ~/Android/openCV/OpenCV-android-sdk 
OPENCV_CAMERA_MODULES:=on 
OPENCV_INSTALL_MODULES:=on 
OPENCV_LIB_TYPE := SHARED 
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk 

LOCAL_MODULE  := detection_based_tracker 
LOCAL_C_INCLUDES += $(LOCAL_PATH) 
LOCAL_SRC_FILES := DetectionBasedTracker_jni.cpp 

LOCAL_LDLIBS  += -lm -llog -ldl -lz -ljnigraphics 
LOCAL_CPPFLAGS += -fexceptions -frtti -std=c++11 

# LOCAL_STATIC_LIBRARIES += dlib 

include $(BUILD_SHARED_LIBRARY) 

也许NDK_PROJECT_PATH=null是什么问题?为什么两个图书馆分开建造?或者还有什么可以解决的问题?我尝试了很多修改Android.mk,但它对我来说是一个谜。 任何帮助或意见将是有用的。

编辑:

当我注释掉LOCAL_STATIC_LIBRARIES += dlib行,我有以下异常:

Build command failed. 
    Error while executing process /home/feli/Android/Sdk/ndk-bundle/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/home/feli/Development/android/test/face-detection/openCVSamplefacedetection/src/main/jni/Android.mk NDK_APPLICATION_MK=/home/feli/Development/android/test/face-detection/openCVSamplefacedetection/src/main/jni/Application.mk APP_ABI=mips64 NDK_ALL_ABIS=mips64 NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=/home/feli/Development/android/test/face-detection/openCVSamplefacedetection/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/home/feli/Development/android/test/face-detection/openCVSamplefacedetection/build/intermediates/ndkBuild/debug/lib /home/feli/Development/android/test/face-detection/openCVSamplefacedetection/build/intermediates/ndkBuild/debug/obj/local/mips64/libdetection_based_tracker.so} 
    [mips64] Compile++  : detection_based_tracker <= DetectionBasedTracker_jni.cpp 
    [mips64] Compile++  : dlib <= source.cpp 
    In file included from /home/feli/Development/android/test/face-detection/openCVSamplefacedetection/src/main/jni/dlib/dlib/all/source.cpp:76: 
    In file included from /home/feli/Development/android/test/face-detection/openCVSamplefacedetection/src/main/jni/dlib/dlib/all/../gui_widgets/fonts.cpp:14: 
    /home/feli/Development/android/test/face-detection/openCVSamplefacedetection/src/main/jni/dlib/dlib/all/../gui_widgets/nativefont.h:27:10: fatal error: 'X11/Xlib.h' file not found 
    #include <X11/Xlib.h> 
      ^~~~~~~~~~~~ 
    1 error generated. 
    make: *** [/home/feli/Development/android/test/face-detection/openCVSamplefacedetection/build/intermediates/ndkBuild/debug/obj/local/mips64/objs-debug/dlib//home/feli/Development/android/test/face-detection/openCVSamplefacedetection/src/main/jni/dlib/dlib/all/source.o] Error 1 
+0

你真的需要MIPS构建吗?如果您打算在ARM设备上运行您的应用程序,请将** abiFilters =“armeabi_v7a”**添加到您的** build.gradle **脚本中。 –

+0

我在abi arm64-v8a上运行,但我也在修改本地C++代码,所以我想我还需要构建它。 – bendaf

+0

您不应该评论'LOCAL_STATIC_LIBRARIES + = dlib' –

回答

2

dlib使用cmake的,这是不是一个简单的设置。体验专家可能需要很长时间才能为此库准备脚本。

我建议您用cmake而不是ndk-build构建您的本机库。你可以找到一个使用OpenCv on GitHub的本地库的例子。

另外,我建议你从abiFilters开始,只设置一个最相关的ABI,只有当你看到所有东西都适合你时,才可以为其他ABI构建你的项目。请记住,对于一些图书馆移植到所有ABI可能会很棘手。如果你没有一个平台对某些ABI进行至少简单的完整性检查,那么建立它就没有意义。

+0

谢谢,我会尽力的! – bendaf