Skip to content

Instantly share code, notes, and snippets.

@ibaiGorordo
Last active July 7, 2022 12:15
Show Gist options
  • Save ibaiGorordo/ebfdb97cbd29a3bccea19040f96f8f34 to your computer and use it in GitHub Desktop.
Save ibaiGorordo/ebfdb97cbd29a3bccea19040f96f8f34 to your computer and use it in GitHub Desktop.
Dockerfile for building the depthai-core library for Android
#
# Run in the terminal
# - Build:
# ```
# docker build . -t depthai-builder -f depthai-android.Dockerfile
# ```
# - Create and Copy the prebuilt libraries into the host computer
# ```
# docker create -ti --name depthai depthai-builder bash
# docker cp depthai:/depthai_build .
# docker rm -f depthai
# ```
# - (Optional for manually copying or other modifications):
# ```
# docker run -it depthai-builder bash
# ```
# Ref: https://github.com/tensorflow/tensorflow/blob/e2b8ad111d87697a3e62a668e75127fb5d685011/tensorflow/tools/dockerfiles/tflite-android.Dockerfile
FROM tensorflow/tensorflow:devel
ENV ANDROID_DEV_HOME /android
RUN mkdir -p ${ANDROID_DEV_HOME}
RUN apt-get install -y --no-install-recommends default-jdk
# Install Android SDK.
ENV ANDROID_SDK_FILENAME commandlinetools-linux-6858069_latest.zip
ENV ANDROID_SDK_URL https://dl.google.com/android/repository/${ANDROID_SDK_FILENAME}
ENV ANDROID_API_LEVEL 23
ENV ANDROID_NDK_API_LEVEL 21
# Build Tools Version liable to change.
ENV ANDROID_BUILD_TOOLS_VERSION 30.0.0
ENV ANDROID_SDK_HOME ${ANDROID_DEV_HOME}/sdk
RUN mkdir -p ${ANDROID_SDK_HOME}/cmdline-tools
ENV PATH ${PATH}:${ANDROID_SDK_HOME}/cmdline-tools/latest/bin:${ANDROID_SDK_HOME}/platform-tools
RUN cd ${ANDROID_DEV_HOME} && \
wget -q ${ANDROID_SDK_URL} && \
unzip ${ANDROID_SDK_FILENAME} -d /tmp && \
mv /tmp/cmdline-tools ${ANDROID_SDK_HOME}/cmdline-tools/latest && \
rm ${ANDROID_SDK_FILENAME}
# Install Android NDK.
ENV ANDROID_NDK_FILENAME android-ndk-r19c-linux-x86_64.zip
ENV ANDROID_NDK_URL https://dl.google.com/android/repository/${ANDROID_NDK_FILENAME}
ENV ANDROID_NDK_HOME ${ANDROID_DEV_HOME}/ndk
ENV PATH ${PATH}:${ANDROID_NDK_HOME}
RUN cd ${ANDROID_DEV_HOME} && \
wget -q ${ANDROID_NDK_URL} && \
unzip ${ANDROID_NDK_FILENAME} -d ${ANDROID_DEV_HOME} && \
rm ${ANDROID_NDK_FILENAME} && \
bash -c "ln -s ${ANDROID_DEV_HOME}/android-ndk-* ${ANDROID_NDK_HOME}"
# Make android ndk executable to all users.
RUN chmod -R go=u ${ANDROID_DEV_HOME}
RUN yes | /android/sdk/cmdline-tools/latest/bin/sdkmanager --licenses
RUN /android/sdk/cmdline-tools/latest/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS_VERSION}"
RUN /android/sdk/cmdline-tools/latest/bin/sdkmanager "platform-tools"
RUN /android/sdk/cmdline-tools/latest/bin/sdkmanager "platforms;android-${ANDROID_API_LEVEL}"
RUN /android/sdk/cmdline-tools/latest/bin/sdkmanager "cmake;3.18.1"
RUN git clone https://github.com/luxonis/depthai-core.git --recursive
WORKDIR "depthai-core"
RUN apt-get install -y ninja-build ccache
RUN mkdir build && cd build && \
/android/sdk/cmake/3.18.1/bin/cmake \
-S.. \
-DANDROID_ABI=arm64-v8a \
-DCMAKE_BUILD_TYPE=Release \
-DANDROID_PLATFORM=android-24 \
-DANDROID_NDK=${ANDROID_NDK_HOME} \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DCMAKE_FIND_ROOT_PATH=${ANDROID_NDK_HOME} \
-DANDROID_TOOLCHAIN=clang \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_PREFIX="./install/" \
-DCMAKE_INSTALL_LIBDIR=lib \
-DDEPTHAI_BUILD_EXAMPLES=OFF \
-DCMAKE_CXX_FLAGS="-llog"
RUN cd build && make -j16
RUN mkdir /depthai_build && \
cp /depthai-core/build/libdepthai-core.so /depthai_build
# RUN mkdir build && cd build && \
# /android/sdk/cmake/3.18.1/bin/cmake \
# -S.. \
# -DCMAKE_SYSTEM_NAME=Android \
# -DCMAKE_EXPORT_COMPILE_COMMANDS=ON\
# -DCMAKE_SYSTEM_VERSION=24 \
# -DANDROID_PLATFORM=android-24 \
# -DANDROID_ABI=arm64-v8a \
# -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
# -DANDROID_NDK=${ANDROID_NDK_HOME} \
# -DCMAKE_ANDROID_NDK=${ANDROID_NDK_HOME} \
# -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
# -DCMAKE_MAKE_PROGRAM=${ANDROID_SDK_HOME}/cmake/3.18.1/bin/ninja \
# -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=arm64-v8a \
# -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=arm64-v8a \
# -DCMAKE_BUILD_TYPE=Release\
# -DCMAKE_CXX_FLAGS="-llog"\
# -Bbuild -D'BUILD_SHARED_LIBS=ON' -GNinja
# RUN cd build && /android/sdk/cmake/3.18.1/bin/cmake --build build --parallel
# RUN mkdir /depthai_build && \
# cp /depthai-core/build/build/arm64-v8a/libdepthai-core.so /depthai_build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment