我是一名android开发人员,但我对Android并不熟悉,请帮助我,或者告诉我您还需要什么/如何解决这类问题。
我在安卓示例中使用了这 dlib,官方的用于android库的opencv和我希望将两者集成到一个应用程序中。当我试图构建项目时,我会得到以下错误:
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.我最初的猜测是,我还没有将source.cpp包含在我的Android.mk中,但是将它放在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发布于 2017-07-31 08:19:29
dlib使用cmake,它不是一个简单的设置。专业人员可能需要很长时间才能为这个库准备ndk构建脚本。
我建议您使用cmake构建您的本机库,而不是使用ndk构建。您可以找到一个使用OpenCv 论GitHub的本机库示例。
另外,我建议您从abiFilters开始,将其设置为一个最相关的ABI,并且只有当您看到一切都适合您时,您才能为其他ABI构建您的项目。请记住,对于某些库来说,移植到所有ABI可能是很棘手的。而且,如果你没有一个平台来对某些ABI进行至少一个简短的理智检查,那么构建它是没有意义的。
https://stackoverflow.com/questions/45370772
复制相似问题