2022-03-25 23:28:16 +08:00
# Build for Android
- [Build for Android ](#build-for-android )
- [Build From Source ](#build-from-source )
- [Install Toolchains ](#install-toolchains )
- [Install Dependencies ](#install-dependencies )
- [Install Dependencies for SDK ](#install-dependencies-for-sdk )
- [Build MMDeploy ](#build-mmdeploy )
- [Build Options Spec ](#build-options-spec )
2022-08-04 14:33:27 +08:00
- [Build SDK and Demos ](#build-sdk-and-demos )
2022-03-25 23:28:16 +08:00
2022-06-17 09:19:10 +08:00
______________________________________________________________________
2022-03-25 23:28:16 +08:00
MMDeploy provides cross compile for android platform.
Model converter is executed on linux platform, and SDK is executed on android platform.
Here are two steps for android build.
2022-08-15 10:18:17 +08:00
1. Build model converter on linux, please refer to [How to build linux ](linux-x86_64.md )
2022-03-25 23:28:16 +08:00
2. Build SDK using android toolchain on linux.
This doc is only for how to build SDK using android toolchain on linux.
## Build From Source
### Install Toolchains
- cmake
2022-06-17 09:19:10 +08:00
**Make sure cmake version >= 3.14.0** . If not, you can follow instructions below to install cmake 3.20.0. For more versions of cmake, please refer to [cmake website ](https://cmake.org/install ).
2022-03-25 23:28:16 +08:00
2022-06-17 09:19:10 +08:00
```bash
wget https://github.com/Kitware/CMake/releases/download/v3.20.0/cmake-3.20.0-linux-x86_64.tar.gz
tar -xzvf cmake-3.20.0-linux-x86_64.tar.gz
sudo ln -sf $(pwd)/cmake-3.20.0-linux-x86_64/bin/* /usr/bin/
```
2022-03-25 23:28:16 +08:00
- ANDROID NDK 19+
2022-07-28 21:11:19 +08:00
**Make sure android ndk version >= 19.0** . If not, you can follow instructions below to install android ndk r23c. For more versions of android ndk, please refer to [android ndk website ](https://developer.android.com/ndk/downloads ).
2022-03-25 23:28:16 +08:00
2022-06-17 09:19:10 +08:00
```bash
2022-07-28 21:11:19 +08:00
wget https://dl.google.com/android/repository/android-ndk-r23c-linux.zip
unzip android-ndk-r23c-linux.zip
cd android-ndk-r23c
2022-06-17 09:19:10 +08:00
export NDK_PATH=${PWD}
```
2022-03-25 23:28:16 +08:00
### Install Dependencies
#### Install Dependencies for SDK
You can skip this chapter if only interested in model converter.
2022-06-17 09:19:10 +08:00
2022-03-25 23:28:16 +08:00
< table >
< thead >
< tr >
< th > NAME < / th >
< th > INSTALLATION < / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > OpenCV< br > (>=3.0) < / td >
< td >
< pre > < code >
2022-07-28 21:11:19 +08:00
export OPENCV_VERSION=4.6.0
2022-03-25 23:28:16 +08:00
wget https://github.com/opencv/opencv/releases/download/${OPENCV_VERSION}/opencv-${OPENCV_VERSION}-android-sdk.zip
unzip opencv-${OPENCV_VERSION}-android-sdk.zip
export OPENCV_ANDROID_SDK_DIR=${PWD}/OpenCV-android-sdk
< / code > < / pre >
< / td >
2022-06-17 09:19:10 +08:00
< / tr >
2022-03-25 23:28:16 +08:00
< tr >
< td > ncnn < / td >
< td > A high-performance neural network inference computing framework supporting for android.< / br >
2022-11-29 20:37:06 +08:00
< b > Now, MMDeploy supports 20221128 and has to use < code > git clone< / code > to download it. For supported android ABI, see < a href = 'https://github.com/Tencent/ncnn/releases' > here < / a > . < / b > < br >
2022-03-25 23:28:16 +08:00
< pre > < code >
2022-11-29 20:37:06 +08:00
git clone -b 20221128 https://github.com/Tencent/ncnn.git
2022-03-25 23:28:16 +08:00
cd ncnn
git submodule update --init
export NCNN_DIR=${PWD}
2022-07-28 21:11:19 +08:00
export ANDROID_ABI=arm64-v8a
mkdir -p build\_${ANDROID_ABI}
cd build\_${ANDROID_ABI}
cmake -DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake -DANDROID_ABI="${ANDROID_ABI}" -DANDROID_PLATFORM=android-30 -DNCNN_VULKAN=ON -DNCNN_DISABLE_EXCEPTION=OFF -DNCNN_DISABLE_RTTI=OFF ..
make -j$(nproc) install
2022-03-25 23:28:16 +08:00
< / code > < / pre >
2022-07-28 21:11:19 +08:00
< / td >
2022-03-25 23:28:16 +08:00
< / tr >
2022-07-07 14:29:45 +08:00
< tr >
< td > OpenJDK < / td >
< td > It is necessary for building Java API.< / br >
See < a href = 'https://github.com/open-mmlab/mmdeploy/blob/master/csrc/mmdeploy/apis/java/README.md' > Java API build < / a > for building tutorials.
< / td >
< / tr >
2022-03-25 23:28:16 +08:00
< / tbody >
< / table >
### Build MMDeploy
2022-06-17 09:19:10 +08:00
2022-08-04 14:33:27 +08:00
#### Build SDK and Demos
2022-06-17 09:19:10 +08:00
2022-03-25 23:28:16 +08:00
MMDeploy provides a recipe as shown below for building SDK with ncnn as inference engine for android.
- cpu + ncnn
```Bash
2022-07-28 21:11:19 +08:00
export ANDROID_ABI=arm64-v8a
2022-03-25 23:28:16 +08:00
cd ${MMDEPLOY_DIR}
2022-07-28 21:11:19 +08:00
mkdir -p build_${ANDROID_ABI} & & cd build_${ANDROID_ABI}
2022-03-25 23:28:16 +08:00
cmake .. \
-DMMDEPLOY_BUILD_SDK=ON \
2022-06-29 11:02:08 +08:00
-DMMDEPLOY_BUILD_SDK_JAVA_API=ON \
2022-08-04 14:33:27 +08:00
-DMMDEPLOY_BUILD_EXAMPLES=ON \
2022-07-28 21:11:19 +08:00
-DOpenCV_DIR=${OPENCV_ANDROID_SDK_DIR}/sdk/native/jni/abi-${ANDROID_ABI} \
-Dncnn_DIR=${NCNN_DIR}/build_${ANDROID_ABI}/install/lib/cmake/ncnn \
2022-03-25 23:28:16 +08:00
-DMMDEPLOY_TARGET_BACKENDS=ncnn \
2022-07-28 21:11:19 +08:00
-DMMDEPLOY_SHARED_LIBS=ON \
2022-03-25 23:28:16 +08:00
-DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake \
2022-07-28 21:11:19 +08:00
-DANDROID_ABI=${ANDROID_ABI} \
2022-03-25 23:28:16 +08:00
-DANDROID_PLATFORM=android-30 \
-DANDROID_CPP_FEATURES="rtti exceptions"
make -j$(nproc) & & make install
```
2022-08-19 10:54:09 +08:00
Please check [cmake build option spec ](cmake_option.md )