Run your Android CI in Google Cloud Build

Martin Bonnin
Aug 28, 2018 · 4 min read
Setting up docker containers is not as hard as you may think!

1. Fork and clone the tutorial repo

git clone
git clone

2. Create a new Google Cloud project and enable Cloud Build API

3. Create your docker cloud-builder image and upload it to the Google container registry

# If you haven't already, install gcloud from these instructions: 
cd android-cloud-build-sample/cloud-builder
gcloud auth login
gcloud config set project cloudbuildsample
gcloud builds submit --config cloudbuild.yaml
# You now have a docker image with gradle and the android SDK
# uploaded to the google container registry

# Install Dependencies
RUN apt-get update \
&& apt-get install -y wget zip unzip \
&& mkdir -p /opt/android-sdk-linux

ENV ANDROID_HOME /opt/android-sdk-linux

# Download Android SDK tools
RUN wget -q "" -O \
&& unzip -q -d $ANDROID_HOME \
&& rm


# Install Android SDK components
RUN echo y | sdkmanager --install 'platforms;android-27' "build-tools;27.0.3" "platform-tools"

4. Speedup: cache your .gradle files !

# Install the wrapper script
COPY gradle-build /bin/
# unzip command might fail the first time if does not 
# exist. That's okay
unzip -o -q
./gradlew $@
zip -qr .gradle
echo "Exit status is: $status"
exit $status

5. Create the github triggers

# get the cache from cloud storage
- name:
args: ['cp', 'gs://gradle_cache_$PROJECT_ID/', '']
# build the app
- name: '$PROJECT_ID/android-builder'
entrypoint: 'gradle-build'
args: ['-g', '.gradle', 'assemble']
# push the cache to cloud storage
- name:
args: ['cp', '', 'gs://gradle_cache_$PROJECT_ID/']

6. That’s it, you’re done !

Yay ! All Green !

Wrap up




The home for videos that matter

Thanks to Klemen Sever, Julie Lambert, and Anne-So.

Martin Bonnin

Written by


The home for videos that matter