compile dlib y opencv con ndk de android

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

Soy un desarrollador de Android, pero soy nuevo en Android NDK, por favor, ayúdame o dime qué más necesitarías o cómo intentarías resolver este tipo de problema.

Utilicé este dlib para el ejemplo de Android y el opencv oficial para la biblioteca de Android y me gustaría integrar los dos en una aplicación. Cuando intento construir el proyecto, aparece el siguiente error:

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. 

Mi primera suposición fue que no incluí / source el archivo source.cpp en mi Android.mk, pero colocarlo en los archivos src no resolvió el problema. Aquí está mi 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) 

Tal vez el NDK_PROJECT_PATH=null es el problema? ¿Por qué las dos bibliotecas están construyendo por separado? ¿O qué más puede ser el problema? Intenté mucho modificar el Android.mk, pero está funcionando es un misterio para mí. Cualquier ayuda u opinión sería útil.

EDIT:

Cuando comento fuera de la LOCAL_STATIC_LIBRARIES += dlib , obtuve la siguiente excepción:

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 usa cmake , y no es una configuración trivial. Un profesional de la experiencia puede tardar mucho tiempo en preparar los ndk-build para esta biblioteca.

Le sugiero que cmake su biblioteca nativa con cmake , en lugar de ndk-build . Puede encontrar un ejemplo de una biblioteca nativa que usa OpenCv en GitHub .

Además, le sugiero que comience con los abiFilters configurados para un solo ABI más relevante, y solo cuando vea que todo funciona para usted, puede construir su proyecto para otros ABI. Recuerde que para algunas bibliotecas, la transferencia a todas las ABI puede ser complicada. Y si no tiene una plataforma para realizar al menos una breve comprobación de validez para algunos ABI, no tiene sentido construir para ello.


HighResolutionMusic.com - Download Hi-Res Songs

1 Alan Walker

Lily flac

Alan Walker. 2018. Writer: Alan Walker;Lars Kristian Rosness;Magnus Bertelsen;K-391;Didrik Handlykken;Marcus Arnbekk.
2 Skylar Grey

Everything I Need flac

Skylar Grey. 2018. Writer: Elliott Taylor;Rupert Gregson-Williams;Skylar Grey.
3 Westlife

Hello My Love flac

Westlife. 2019. Writer: Steve Mac;Ed Sheeran.
4 Alec Benjamin

Let Me Down Slowly flac

Alec Benjamin. 2019. Writer: Alec Benjamin;Sir Nolan;Michael Pollack.
5 Alan Walker

Lost Control flac

Alan Walker. 2018. Writer: Alan Walker;Thomas Troelsen;Mood Melodies;Sorana;Fredrik Borch Olsen;Magnus "Magnify" Martinsen.
6 Sam Smith

Fire On Fire flac

Sam Smith. 2018. Writer: Steve Mac;Sam Smith.
7 Conor Maynard

Way Back Home (Sam Feldt Edit) flac

Conor Maynard. 2018. Writer: Ji Hye Lee;Shaun.
8 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.
9 Post Malone

Sunflower flac

Post Malone. 2018. Writer: Carl Rosen;Louis Bell;Billy Walsh;Carter Lang;Swae Lee;Post Malone.
10 The Chainsmokers

Hope flac

The Chainsmokers. 2018. Writer: Kate Morgan;Chris Lyon;Alex Pall;Andrew Taggart.
11 Normani

Dancing With A Stranger flac

Normani. 2019. Writer: Mikkel S. Eriksen;Tor Hermansen;Jimmy Napes;Normani;Sam Smith.
12 Deniz Koyu

Eclipse flac

Deniz Koyu. 2019.
13 Gesaffelstein

Lost In The Fire flac

Gesaffelstein. 2019. Writer: Ahmad Balshe;Nate Donmoyer;Gesaffelstein;DaHeala;The Weeknd.
14 Alan Walker

I Don't Wanna Go flac

Alan Walker. 2018.
15 Backstreet Boys

No Place flac

Backstreet Boys. 2019.
16 Loren Gray

Anti-Everything flac

Loren Gray. 2019.
17 Imagine Dragons

Believer flac

Imagine Dragons. 2019. Writer: Robin Fredriksson;Mattman & Robin;Wayne Sermon;Dan Reynolds;Daniel Platzman;Ben McKee;Justin Tranter;Mattias Larsson.
18 Ran-D

Zombie (Bassjackers Remix) flac

Ran-D. 2019.
19 Calvin Harris

Giant flac

Calvin Harris. 2019. Writer: Calvin Harris;Rag'n'Bone Man;Jamie Hartman;Troy Miller.
20 Tom & Jame⁠

Waiting flac

Tom & Jame⁠. 2019.

Related questions

Hot questions

Language

Popular Tags