################################################################################
###  Build Android                                                           ###
################################################################################
# Different from all others
FROM saschpe/android-ndk:31-jdk11.0.13_8-ndk23.0.7599858-cmake3.18.1 as builderandroid
RUN apt update && apt install -y lsb-release g++ build-essential wget git libssl-dev pkg-config zip unzip
RUN wget https://github.com/Kitware/CMake/releases/download/v3.30.2/cmake-3.30.2.tar.gz
RUN tar -xvf cmake-3.30.2.tar.gz
RUN cd cmake-3.30.2 && ./bootstrap && make -j && make install
RUN curl -s "https://get.sdkman.io" | bash
RUN /bin/bash -c "source /root/.sdkman/bin/sdkman-init.sh ; sdk install gradle 7.6.2"
RUN sdkmanager "build-tools;30.0.3" "cmake;3.22.1"
ENV ANDROID_SDK_VERSION="31"
ENV ANDROID_HOME="/opt/android-sdk-linux"
ENV ANDROID_NDK_VERSION="23.0.7599858"
ENV ANDROID_NDK_HOME="$ANDROID_HOME/ndk/$ANDROID_NDK_VERSION"
ENV GRADLE_DIR="/home/builder/gradle"
ENV GRADLE_HOME="$GRADLE_DIR/current"
ENV GRADLE_USER_HOME=$GRADLE_HOME
ENV PATH="$ANDROID_HOME:$GRADLE_HOME/bin:$ANDROID_NDK_HOME:$PATH"
RUN useradd builder -m
RUN mkdir -p /home/builder/cc3dsfs
RUN mkdir -p /home/builder/building
RUN chown -R builder:builder /home/builder
WORKDIR /home/builder/building
COPY  docker_build_starter /
RUN chmod +x /docker_build_starter
RUN chown -R builder:builder $ANDROID_HOME
RUN mkdir -p $GRADLE_DIR
RUN mv /root/.sdkman/candidates/gradle/* $GRADLE_DIR/
RUN chown -R builder:builder $GRADLE_DIR
USER builder
CMD /docker_build_starter docker-scripts/docker_build_android
