└── Dockerfile /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk-slim 2 | 3 | # Install required packages: 4 | # - curl: to download the Android SDK Tools 5 | # - git: fetching sources occurs inside the container 6 | # - libgl1-mesa-glx: for Android emulator 7 | # - libpulse0: for Android emulator 8 | # - openssh-client: for Git-related operations 9 | # - procps: for `ps`, required by Jenkins Docker Pipeline Plugin 10 | # - rsync: to help sync Gradle caches 11 | RUN apt-get update && \ 12 | DEBIAN_FRONTEND=noninteractive \ 13 | apt-get install -y --no-install-recommends \ 14 | curl \ 15 | git \ 16 | libgl1-mesa-glx \ 17 | libpulse0 \ 18 | openssh-client \ 19 | procps \ 20 | rsync \ 21 | unzip && \ 22 | rm -rf /var/lib/apt/lists/* 23 | 24 | # Create an android user/group, with Jenkins-compatible UID 25 | RUN groupadd --gid 1000 android && \ 26 | useradd --uid 1000 --gid 1000 --create-home android 27 | 28 | # Export ANDROID_HOME, so that other tools can find the SDK 29 | ENV ANDROID_HOME /opt/android/sdk 30 | 31 | # Create the ANDROID_HOME directory for the android user 32 | RUN mkdir -p ${ANDROID_HOME} && \ 33 | chown -R android:android ${ANDROID_HOME} 34 | 35 | # Switch to the android user 36 | USER android 37 | ENV HOME /home/android 38 | 39 | # Enable Java options for Docker 40 | ENV JAVA_TOOL_OPTIONS -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap 41 | 42 | # Put the Android SDK Tools on the PATH 43 | ENV PATH=${ANDROID_HOME}/tools:${ANDROID_HOME}/emulator:${ANDROID_HOME}/cmdline-tools/tools/bin:${ANDROID_HOME}/platform-tools:${PATH} 44 | 45 | # Stop sdkmanager from complaining 46 | RUN mkdir ~/.android && touch ~/.android/repositories.cfg 47 | 48 | # Define the download URL and SHA-256 checksum of the Android SDK Tools; 49 | # both can be found at https://developer.android.com/studio/index.html#command-tools 50 | ARG ANDROID_SDK_URL=https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip 51 | ARG ANDROID_SDK_CHECKSUM=f10f9d5bca53cc27e2d210be2cbc7c0f1ee906ad9b868748d74d62e10f2c8275 52 | 53 | # Download the Android SDK Tools, verify the checksum, extract to ANDROID_HOME, then 54 | # remove everything but sdkmanager and its dependencies to keep the layer size small 55 | RUN curl --silent --show-error --fail --retry 1 --output /tmp/sdk.zip --location ${ANDROID_SDK_URL} && \ 56 | echo "${ANDROID_SDK_CHECKSUM} /tmp/sdk.zip" > /tmp/checksum && \ 57 | sha256sum -c /tmp/checksum > /dev/null && \ 58 | unzip -q /tmp/sdk.zip -d ${ANDROID_HOME}/cmdline-tools && \ 59 | rm /tmp/checksum /tmp/sdk.zip 60 | 61 | # Accept all SDK licences 62 | RUN sdkmanager --verbose --update && \ 63 | yes | sdkmanager --licenses 64 | 65 | # Update the Android SDK Tools to the latest, and install the basics 66 | RUN sdkmanager --verbose \ 67 | tools \ 68 | platform-tools \ 69 | emulator 70 | 71 | # Install the desired platform version and Build Tools 72 | RUN sdkmanager --verbose --update && \ 73 | sdkmanager --verbose --install \ 74 | 'platforms;android-29' \ 75 | 'build-tools;29.0.3' 76 | --------------------------------------------------------------------------------