Android docker gradle-6.x build container

Marcel Lamm
Nov 7, 2020

So you want to compile your fancy android app within a docker container?

Can be used e.g. in a CI-pipeline to build the .apk artifacts.

I am using 2 docker container, bundled together in a sh script. Placed in a scripts/ directory.


FROM gradle:6.7-jdk8
USER root

ANDROID_HOME="/usr/local/android-sdk" \

WORKDIR /opt/workspace

# Download Android SDK
RUN mkdir "$ANDROID_HOME" .android \
&& cd "$ANDROID_HOME" \
&& curl -o $SDK_URL \
&& unzip \
&& rm

RUN mkdir "$ANDROID_HOME/licenses" || true \
&& echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_HOME/licenses/android-sdk-license"

RUN yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME --licenses

# Install Android Build Tool and Libraries
RUN $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME --update
RUN $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
"platforms;android-${ANDROID_VERSION}" \

# Install Build Essentials
RUN apt-get update && apt-get install build-essential -y && apt-get install file -y && apt-get install apt-utils -y

RUN echo "Europe/Berlin" > /etc/timezone


FROM base-build-superapp:latest

RUN mkdir SuperAppProject

ADD SuperAppProject/build.gradle SuperAppProject/build.gradle
ADD SuperAppProject/ SuperAppProject/
ADD SuperAppProject/settings.gradle SuperAppProject/settings.gradle
ADD SuperAppProject/SuperApp SuperAppProject/SuperApp



set -e

docker build -t base-build-superapp -f ./scripts/base-build-container/Dockerfile .
docker build -t build-superapp -f ./scripts/build-container/Dockerfile .

# compile all the stuff
docker run -v $(pwd):/opt/workspace --rm busybox rm -rf /opt/workspace/out
mkdir -p ./out

docker run --rm -v $(pwd)/out:/opt/workspace/SuperAppProject/SuperApp/build/outputs -w /opt/workspace/SuperAppProject build-superapp:latest /bin/sh -c "gradle build"