1 minute read

For a recent project, I had to include the Android SDK build tools as part of a Jenkins Dockerfile. No problem. Download and execute installer, right?

Wrong. With Google installers come license agreements, and I needed a way to reliably accept the terms and conditions of the installer and it's dependencies automatically. Here's what my Dockerfile looks like:

FROM jenkinsci/jenkins:2.0-beta-1
USER root
RUN mkdir /var/log/jenkins
RUN mkdir /var/cache/jenkins
RUN chown -R jenkins:jenkins /var/log/jenkins
RUN chown -R jenkins:jenkins /var/cache/jenkins

RUN apt-get update && apt-get install -y apt-transport-https
RUN apt-get -q -y install lsof

RUN wget https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz -O /opt/android-sdk.tgz
RUN tar zxvf /opt/android-sdk.tgz -C /opt/
RUN rm /opt/android-sdk.tgz

RUN >/etc/profile.d/android.sh
RUN sed -i '$ a\export ANDROID_HOME="/opt/android-sdk-linux"' /etc/profile.d/android.sh
RUN sed -i '$ a\export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH"' /etc/profile.d/android.sh
RUN . /etc/profile
RUN apt-get install git-core
RUN ( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) | /opt/android-sdk-linux/tools/android update sdk --no-ui --filter platform-tools,android-24,build-tools-24.0.1,tools,extra-android-support,extra-android-m2repository
RUN chmod -R 755 /opt/android-sdk-linux
RUN dpkg --add-architecture i386
USER jenkins
ENV JAVA_OPTS="-Xmx8192m"

Not complicated, really, but worth documenting for others out there.

Backwards-compatibility for Build Tools in Jenkins

I have 'build-tools-24.0.1' in there because the app I'm working with has not been upgraded to the latest version of Gradle, but it's worth noting too because not everyone has the luxury of changing code/compile settings just because Google ships new binaries. Thanks Google, you really know how to break my build. ;*

Instead, I chose to own the responsibility of the version of tools needed on my build nodes for the types of projects I intend to compile on them. Because of this, I need to know the specific android update sdk filter codes that correspond to the pretty package names I see on my workstation in SDK Manager.

To list the codes that you might need in your own update filter, use the following command under your Android SDK tools folder:

android list sdk -a -e

...which displays a list like this:

That is all.

Semi-related Reading: