使用android ndk编译dlib和opencv

bendaf 07/28/2017. 1 answers, 983 views
android android build android-ndk dlib android-studio-2.3

我是Android开发人员,但我是Android NDK的新手,请帮忙,或者告诉我你还需要什么/如何解决这类问题。

我使用这个 dlib用于android示例和官方opencv用于android库 ,我想将这两个集成在一个应用程序中。 当我尝试构建项目时,我收到以下错误:

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,但将它放在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,但它的工作对我来说是一个谜。 任何帮助或意见都会有用。

EDIT:

当我注释掉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            ^~~~~~~~~~~~
  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 

1 Answers


Alex Cohn 07/31/2017.

dlib使用cmake ,它不是一个简单的设置。 体验专业人员可能需要很长时间才能为此库准备ndk-build脚本。

我建议您使用cmake构建本机库,而不是使用ndk-build 。 您可以在GitHub上找到使用OpenCv的本机库示例。

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


HighResolutionMusic.com - Download Hi-Res Songs

1 Alan Walker

Different World flac

Alan Walker. 2018. Writer: Shy Nodi;Alan Walker;Fredrik Borch Olsen;James Njie;Marcus Arnbekk;Gunnar Greve Pettersen;K-391;Corsak;Shy Martin;Magnus Bertelsen.
2

Tell Me It's Over

3 Ariana Grande

​Thank U, Next flac

Ariana Grande. 2018. Writer: Crazy Mike;Scootie;Victoria Monét;Tayla Parx;TBHits;Ariana Grande.
4 Mesto

Wait Another Day flac

Mesto. 2018.
5 Anne-Marie

Rewrite The Stars flac

Anne-Marie. 2018. Writer: Benj Pasek;Justin Paul.
6 Ariana Grande

Imagine flac

Ariana Grande. 2018. Writer: Jameel Roberts;Priscilla Renea;Happy Perez;Andrew "Pop" Wansel;Ariana Grande.
7 Julian Jordan

Glitch flac

Julian Jordan. 2018.
8 Rita Ora

Let You Love Me flac

Rita Ora. 2018. Writer: Rita Ora;Easyfun;Fred Gibson;Noonie Bao;LotusIV;Ilsey Juber.
9 Conor Maynard

How You Love Me flac

Conor Maynard. 2018. Writer: Yoshi Breen;Thom Bridges;Hardwell;Rik Annema;Conor Maynard;Cimo Fränkel;Snoop Dogg.
10 ZAYN

There You Are flac

ZAYN. 2018. Writer: Joe Garrett;Levi Lennox;Michael Hannides;Anthony Hannides;ZAYN.
11 Skylar Grey

Everything I Need flac

Skylar Grey. 2018.
12 Alan Walker

Lost Control flac

Alan Walker. 2018.
13 Alan Walker

Lily flac

Alan Walker. 2018.
14 Fitz And The Tantrums

HandClap flac

Fitz And The Tantrums. 2017. Writer: Fitz And The Tantrums;Eric Frederic;Sam Hollander.
15 (G)I-DLE

POP/STARS flac

(G)I-DLE. 2018. Writer: Riot Music Team;Harloe.
16 ZAYN

Good Years flac

ZAYN. 2018. Writer: Anthony Hannides;Khaled Rohaim;Michael Hannides;ZAYN;Herbie Crichlow.
17 Clean Bandit

Baby flac

Clean Bandit. 2018. Writer: Jack Patterson;Kamille;Jason Evigan;Matthew Knott;Marina;Luis Fonsi.
18 Mark Ronson

Nothing Breaks Like A Heart flac

Mark Ronson. 2018. Writer: Thomas Brenneck;Maxime Picard;Ilsey Juber;Conor Szymanski;Clement Picard;Mark Ronson;Miley Cyrus.
19 Clean Bandit

Mama flac

Clean Bandit. 2018. Writer: Jason Evigan;Jack Patterson;Grace Chatto;Ellie Goulding;Caroline Ailin.
20 Bastille

Grip flac

Bastille. 2018. Writer: Dan Smith;Espen Berg;Joakim Haukaas;Mark Crew;Simen Eriksrud;Thomas Eriksen.

Related questions

Hot questions

Language

Popular Tags