Docker image for Android builds

I’ve been looking for a good and up-to-date Docker image for a while, one that can build Android apk and bundle files as part of a CI/CD pipeline, because the MobileDevOps team stopped updating their image a year and a half ago, their latest image version only supports the Android API level 34 and the Google Play has already enforces API level 35 for a while.

After some searching and a bit of copy-pasting, the Dockerfile finally came together – since I “borrowed” some parts too – I’m sharing it here for anyone who might find it useful:

FROM --platform=linux/amd64 ubuntu:24.04

# 1, Go to: https://developer.android.com/studio#command-tools
# 2, Search for: Command line tools only
# 3, Replace here the version and checksum to the latest
ENV ANDROID_SDK_TOOLS_VERSION 13114758
ENV ANDROID_SDK_TOOLS_CHECKSUM 7ec965280a073311c339e571cd5de778b9975026cfcbe79f2b1cdcb1e15317ee

ENV GRADLE_VERSION 8.14

ENV ANDROID_HOME "/opt/android-sdk-linux"
ENV ANDROID_SDK_ROOT $ANDROID_HOME
ENV PATH $PATH:$ANDROID_HOME/cmdline-tools:$ANDROID_HOME/cmdline-tools/bin:$ANDROID_HOME/platform-tools

ENV DEBIAN_FRONTEND=noninteractive
ENV LANG en_US.UTF-8

# Add base environment
RUN apt-get -qq update
RUN apt-get -qqy --no-install-recommends install \
    apt-utils \
    build-essential \
    openjdk-17-jdk \
    openjdk-17-jre-headless \
    software-properties-common \
    libssl-dev \
    libffi-dev \
    python3-dev \
    cargo \
    pkg-config\  
    libstdc++6 \
    libpulse0 \
    libglu1-mesa \
    openssh-server \
    zip \
    unzip \
    curl \
    lldb \
    git > /dev/null
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* || true
   
# Download and unzip Android SDK Tools
RUN curl -s https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS_VERSION}_latest.zip > /tools.zip \
    && echo "$ANDROID_SDK_TOOLS_CHECKSUM ./tools.zip" | sha256sum -c \
    && unzip -qq /tools.zip -d $ANDROID_HOME \
    && rm -v /tools.zip

# Accept licenses
# Replace <licence-content-here> with your accepted licence files from your desktop SDK.
RUN mkdir -p $ANDROID_HOME/licenses/ \
    && echo "<licence-content-here>" > $ANDROID_HOME/licenses/android-sdk-license \
    && echo "<licence-content-here>" > $ANDROID_HOME/licenses/android-sdk-preview-license \
    && yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager --licenses --sdk_root=${ANDROID_SDK_ROOT}

# Add folder for SDK files 
RUN mkdir -p /home/sdk/.android \
    && mkdir -p /home/sdk/app \
    && touch /home/sdk/.android/repositories.cfg

ENV HOME /home/sdk
WORKDIR $HOME/app

# Install SDKMAN
RUN curl -s "https://get.sdkman.io" | bash
SHELL ["/bin/bash", "-c"]   

# Install Android packages
ADD packages.txt $HOME

# Update sdkmanager
RUN $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT} --update
RUN while read -r pkg; do PKGS="${PKGS}${pkg} "; done < $HOME/packages.txt
RUN $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT} $PKGS
RUN rm $HOME/packages.txt

# Install Gradle
RUN source "${HOME}/.sdkman/bin/sdkman-init.sh" \
    && sdk install gradle ${GRADLE_VERSION}

Place a packages.txt file next to the Dockerfile and update the version numbers as needed:

build-tools;35.0.0
platforms;android-36
platform-tools
extras;android;m2repository
extras;google;m2repository
extras;google;google_play_service

That’s it! 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top