FROM codercom/enterprise-java:ubuntu

# Run everything as root
USER root

ENV ANDROID_SDK_ROOT /usr/lib/android-sdk
ENV ANDROID_HOME ${ANDROID_SDK_ROOT}
RUN mkdir -p ${ANDROID_SDK_ROOT}

# Install cmdline-tools.
RUN cd ${ANDROID_SDK_ROOT} && \
    mkdir cmdline-tools && \
    cd cmdline-tools && \
    wget https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip && \
    unzip *.zip && rm *.zip && \
    mv cmdline-tools latest
ENV PATH ${PATH}:${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin

# Install build tools.
RUN yes | sdkmanager "build-tools;29.0.3"
ENV PATH ${PATH}:${ANDROID_SDK_ROOT}/platform-tools

# Install platform android-29.
RUN yes | sdkmanager "platforms;android-29"

# Packages required for multi-editor support
RUN DEBIAN_FRONTEND="noninteractive" apt-get update -y && \
    apt-get install -y \
    libxtst6 \
    libxrender1 \
    libfontconfig1 \
    libxi6 \
    libgtk-3-0

# Install Android Studio
RUN add-apt-repository ppa:maarten-fonville/android-studio && \
    apt update && \
    apt install -y android-studio && \
    ln -s /opt/android-studio/bin/studio.sh /usr/local/bin/studio

# Set back to coder user
USER coder
