Build Assimp for Android
Assimp is an open source library that allows reading and writing several 3D file formats. In the age of metaverse, If we have to reuse all that investment that we already made in building 3D content — Assimp provides a way. In this article, we are just going to see how to build this library for Android target.
Steps:
- Pull an Ubuntu base docker image
docker pull ubuntu:bionic
2. Run docker and enter into bash
docker run -v <hostfolder>:/data -it ubuntu:bionic /bin/bash
3. Update Ubuntu repos
apt-get update
4. Install the build tools. This may take few minutes to complete.
apt-get install -y git cmake build-essential software-properties-common wget unzip
5. Install the compilers
add-apt-repository ppa:ubuntu-toolchain-r/test && apt-get update && apt-get install -y gcc g++
6. Install Android NDK
export ANDROID_NDK_HOME="/opt/android-ndk"
export ANDROID_NDK_VERSION="r22"
wget -q https://dl.google.com/android/repository/android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip
unzip android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip
mv android-ndk-${ANDROID_NDK_VERSION} /opt/android-ndk
rm android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip
7. Clone the assimp repository
git clone https://github.com/assimp/assimp.git /opt/assimp
cd /opt/assimp/
8. Checkout assimp git repo and apply a patch
cd /opt/assimp/
git checkout master
Apply the following patch to port/AndroidJNI/CMakeLists.txt
9.Build it. -DANDROID_ABI can be one of armeabi-v7a, arm64-v8a, x86 and x86_64
cd /opt/assimp/
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DASSIMP_ANDROID_JNIIOSYSTEM=ON -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake -DANDROID_NDK=${ANDROID_NDK_HOME} -DANDROID_ABI=arm64-v8a -DBUILD_SHARED_LIBS=1 ..
make -j4
The built library can be located in /opt/assimp/build/bin/libassimp.so
If you notice the library size > 100 MB, you may run the NDK strip tool to get rid of the debug symbols bundled in the library
aarch64-linux-android-strip -g -S -d --strip-debug --verbose /opt/assimp/build/bin/libassimp.so