compilare dlib e opencv con Android ndk

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

Sono uno sviluppatore Android, ma sono nuovo di Android NDK, per favore aiuto, o dimmi cos'altro avresti bisogno / come vorresti provare a risolvere questo tipo di problema.

Ho usato questo dlib per l'esempio Android e l' opencv ufficiale per la libreria Android e vorrei integrare le due in una sola applicazione. Quando provo a creare il progetto ottengo il seguente errore:

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. 

La mia prima ipotesi è che non ho incluso il source.cpp nel mio Android.mk ma non lo ho risolto nei file src. Ecco il mio 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) 

Forse NDK_PROJECT_PATH=null è il problema? Del perché le due librerie stanno costruendo separatamente? O quale altro può essere il problema? Ho provato molto a modificare l'Android.mk, ma funziona è un mistero per me. Qualsiasi aiuto o opinione sarebbe utile.

EDIT:

Quando commento la LOCAL_STATIC_LIBRARIES += dlib , ho ottenuto la seguente eccezione:

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 
5 Comments
Alex Cohn 07/28/2017
Hai davvero bisogno di costruire MIPS? Se intendi eseguire la tua app su dispositivi ARM, aggiungi abiFilters= "armeabi_v7a" al tuo script build.gradle .
bendaf 07/30/2017
Sono in esecuzione su abi arm64-v8a, ma sto anche modificando il codice c ++ nativo, quindi suppongo di doverlo anche costruire.
Alex Cohn 07/30/2017
Non si dovrebbe commentare LOCAL_STATIC_LIBRARIES += dlib
bendaf 07/31/2017
Ho modificato la mia domanda, per favore controlla se hai tempo
1 Alex Cohn 07/31/2017
No, non dovresti preoccuparti di NDK_PROJECT_PATH , è così che Android Studio configura la build nativa tramite ndk-build . Ma dlib è strutturato intorno a cmake , quindi dovrebbe riprodurre le impostazioni di costruzione utilizzate lì.

1 Answers


Alex Cohn 07/31/2017.

dlib usa cmake e non è una configurazione banale. Potrebbe essere necessario molto tempo per un professionista esperto per preparare gli script ndk-build per questa libreria.

Ti suggerisco di costruire la tua libreria nativa con cmake , invece di ndk-build . È possibile trovare un esempio di una libreria nativa che utilizza OpenCv su GitHub .

Inoltre, ti suggerisco di iniziare con abiFilters impostato su un solo ABI più rilevante, e solo quando vedi che tutto funziona per te, puoi costruire il tuo progetto per altri ABI. Ricorda che per alcune librerie il porting su tutte le ABI può essere complicato. E se non si dispone di una piattaforma per eseguire almeno un breve controllo di integrità per alcuni ABI, non ha senso costruirlo.

1 comments
bendaf 07/31/2017
Grazie, ci proverò!

HighResolutionMusic.com - Download Hi-Res Songs

1 (G)I-DLE

POP/STARS flac

(G)I-DLE. 2018. Writer: Riot Music Team;Harloe.
2 Ariana Grande

​Thank U, Next flac

Ariana Grande. 2018. Writer: Crazy Mike;Scootie;Victoria Monét;Tayla Parx;TBHits;Ariana Grande.
3 Imagine Dragons

Bad Liar flac

Imagine Dragons. 2018. Writer: Jorgen Odegard;Daniel Platzman;Ben McKee;Wayne Sermon;Aja Volkman;Dan Reynolds.
4 Backstreet Boys

Chances flac

Backstreet Boys. 2018.
5 Clean Bandit

Baby flac

Clean Bandit. 2018. Writer: Jack Patterson;Kamille;Jason Evigan;Matthew Knott;Marina;Luis Fonsi.
6 BTS

Waste It On Me flac

BTS. 2018. Writer: Steve Aoki;Jeff Halavacs;Ryan Ogren;Michael Gazzo;Nate Cyphert;Sean Foreman;RM.
7 BlackPink

Kiss And Make Up flac

BlackPink. 2018. Writer: Soke;Kny Factory;Billboard;Chelcee Grimes;Teddy Park;Marc Vincent;Dua Lipa.
8 Lady Gaga

I'll Never Love Again flac

Lady Gaga. 2018. Writer: Benjamin Rice;Lady Gaga.
9 Kelly Clarkson

Never Enough flac

Kelly Clarkson. 2018. Writer: Benj Pasek;Justin Paul.
10 Fitz And The Tantrums

HandClap flac

Fitz And The Tantrums. 2017. Writer: Fitz And The Tantrums;Eric Frederic;Sam Hollander.
11 Little Mix

Told You So flac

Little Mix. 2018. Writer: Eyelar;MNEK;Raye.
12 Halsey

Without Me flac

Halsey. 2018. Writer: Halsey;Delacey;Louis Bell;Amy Allen;Justin Timberlake;Timbaland;Scott Storch.
13 Cher Lloyd

None Of My Business flac

Cher Lloyd. 2018. Writer: ​iamBADDLUCK;Alexsej Vlasenko;Kate Morgan;Henrik Meinke;Jonas Kalisch;Jeremy Chacon.
14 Bradley Cooper

Always Remember Us This Way flac

Bradley Cooper. 2018. Writer: Lady Gaga;Dave Cobb.
15 Calum Scott

No Matter What flac

Calum Scott. 2018. Writer: Toby Gad;Calum Scott.
16 Ashley Tisdale

Voices In My Head flac

Ashley Tisdale. 2018. Writer: John Feldmann;Ashley Tisdale.
17 Imagine Dragons

Machine flac

Imagine Dragons. 2018. Writer: Wayne Sermon;Daniel Platzman;Dan Reynolds;Ben McKee;Alex Da Kid.
18 Diplo

Close To Me flac

Diplo. 2018. Writer: Ellie Goulding;Savan Kotecha;Peter Svensson;Ilya;Swae Lee;Diplo.
19 Billie Eilish

When The Party's Over flac

Billie Eilish. 2018. Writer: Billie Eilish;FINNEAS.
20 Little Mix

Woman Like Me flac

Little Mix. 2018. Writer: Nicki Minaj;Steve Mac;Ed Sheeran;Jess Glynne.

Related questions

Hot questions

Language

Popular Tags