I am having a hard time in integrating dlib with my android studio NDK project, Basically I want to use the library in my native C++ code, I am not sure about the standard way of doing the same, I have my Android.mk
file which is under app/src/main/jni
as :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := dlib
LOCAL_SRC_FILES := dlib/all/source.cpp
LOCAL_CPPFLAGS = -I/opt/X11/include
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
OPENCVROOT:= /Users/anmoluppal/Downloads/OpenCV-android-sdk
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := ndkDemo
LOCAL_STATIC_LIBRARIES := dlib
LOCAL_SRC_FILES := main.cpp face_detector.cpp face_tracker.cpp ft_data.cpp patch_model.cpp shape_model.cpp
include $(BUILD_SHARED_LIBRARY)
And the Application.mk
file looks something like:
APP_STL := gnustl_static
APP_CPPFLAGS += -fexceptions -frtti
APP_ABI := all
And the project structure is:
+ app
---+ src
-----+ main
-------+ jni
---------+ dlib
---------+ Application.mk
---------+ Android.mk
---------+ (... Other .cpp files)
And I am getting a lot of undefined reference to
errors which are referring to X11
library on Mac, which is indeed installed properly, I want to know if this is the correct way of including a library in NDK project? Or alternatively I need to create a Android.mk
file in dlib
folder as well? Also I am unaware of the main .cpp
files which are required as LOCAL_SRC_FILES
for the .mk
file.
After ndk-build
I get the following output:
[arm64-v8a] Compile++ : ndkDemo <= main.cpp
[arm64-v8a] Compile++ : ndkDemo <= face_detector.cpp
[arm64-v8a] Compile++ : ndkDemo <= face_tracker.cpp
[arm64-v8a] Compile++ : ndkDemo <= ft_data.cpp
[arm64-v8a] Compile++ : ndkDemo <= patch_model.cpp
[arm64-v8a] Compile++ : ndkDemo <= shape_model.cpp
[arm64-v8a] Compile++ : dlib <= source.cpp
[arm64-v8a] StaticLibrary : libdlib.a
[arm64-v8a] SharedLibrary : libndkDemo.so
There are several things you need to consider. First: The libraries you link need to be cross compiled for the respective ABIs. Your Application.mk says all so you need to provide all (arm, x86, MIPS,...). Are your libraries prebuilt? In that case you will need to cross compile them manually.
You are missing the include directories for your libraries. You can include them with :
LOCAL_EXPORT_C_INCLUDES
LOCAL_C_INCLUDES
This is the way to go instead of using CPP-Flags.
There are some other problems in your makefile which you should resolve by inspecting makefiles of other people on stackoverflow or search in the NDK documentation. For example I dont think that you can provide the LOCAL_SRC_FILES like you did, you need to separate them by backslashes like that:
LOCAL_SRC_FILES := \ x.cpp \ y.cpp
Your project structure is fine, I think you are almost there.
Feel free to provide the new version of your makefiles when you resolved the linking errors.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.