Compile and embed Dlib (and, optionally OpenCV) in your Android projects with ease.
From AndroidStudio at tool > SDK Manager > SDK Tools
install:
- LLDB
- CMake
- NDK.
- Clone the repo recursively (to download Dlib).
- Create an Android project with c++11 support.
- Edit the
setup.sh
(Linux user) orsetup.ps1
(Windows user) script:- Replace
AndroidCmake
variable with the path to your Android CMake excutable (is usually inside the androidsdk
folder). - Replace
NDK
variable with the path to your Android NDK (ndk-bundle). - Replace
TOOLCHAIN
variable with the path to your android.toolchain.cmake. - Select the ABIs you want to support among:
armeabi-v7a
,arm64-v8a
,x86
andx86_64
. - Edit the
MIN_SDK
value, the minimum supported is16
. - Set the
PROJECT_PATH
variable according to your Android project path.
- Replace
- Launch the script and wait until completion (comment what you don't need!). It will:
- Compile Dlib for multiple ABI,
- Copy the Dlib headers and
libdlib.so
to your project, - Copy the
lib_opencv4.so
to your project.
- Edit your
CMakeLists
like this one. - Update your
build.gradle
(app) file in order to support CMake example. - Build and Enjoy!
A complete tutorial is available here.
On my github you can find here, a complete Android application that uses Dlib and OpenCV 4.
Inside the folder prebuilt
you can find a set of ready-to-use libdlib.so
, compiled from Dlib 19.16 source code.
The .so
are built for the ABIs: armeabi-v7a
, arm64-v8a
, x86
and x86_64
; with a 16 as min-sdk
.
For Windows users: If the PowerShell complains about the script you can try this:
1. Open the Windows PowerShell
2. Move to the script location
3. type and execute: powershell -ExecutionPolicy ByPass -File setup.ps1
Bash script NOT TESTED!!