dlib-for-android
dlib-for-android copied to clipboard
Compile and embed Dlib in your Android projects with ease.
Dlib-for-Android
Compile and embed Dlib (and, optionally OpenCV) in your Android projects with ease.
Prerequisites
From AndroidStudio at tool > SDK Manager > SDK Tools install:
- LLDB
- CMake
- NDK.
Usage
- 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
AndroidCmakevariable with the path to your Android CMake excutable (is usually inside the androidsdkfolder). - Replace
NDKvariable with the path to your Android NDK (ndk-bundle). - Replace
TOOLCHAINvariable with the path to your android.toolchain.cmake. - Select the ABIs you want to support among:
armeabi-v7a,arm64-v8a,x86andx86_64. - Edit the
MIN_SDKvalue, the minimum supported is16. - Set the
PROJECT_PATHvariable 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.soto your project, - Copy the
lib_opencv4.soto your project.
- Edit your
CMakeListslike this one. - Update your
build.gradle(app) file in order to support CMake example. - Build and Enjoy!
A complete tutorial is available here.
Examples
On my github you can find here, a complete Android application that uses Dlib and OpenCV 4.
Prebuilt library
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.
Troubleshooting
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
Warning
Bash script NOT TESTED!!