Build Android CI with Bitbucket Pipeline and HockeyApp Part 1

Nsikak Thompson
DroidPlate
Published in
4 min readFeb 1, 2018

Continuous Integration (CI) is the process of automating the build and testing of code every time a team member commits changes to version control.

“Continuous Integration doesn’t get rid of bugs, but it does make them dramatically easier to find and remove.”

— Martin Fowler, Chief Scientist, ThoughtWorks

Configuring a CI can be tricky for Android apps. But let’s see how quick it is to build an Android app with Bitbucket Pipeline and deliver it with Hockey app.

What is Bitbucket pipelines?

Bitbucket Pipeline is a continuous integration service that Atlassian geniously integrate in their git solution Bitbucket last year. It’s based on Docker container technology and require only a YAML file to start using it.

Create a Repo on Bitbucket

To begin this process you should have a repository(hosting your Android project) on bitbucket. If you have one already Skip this step. For new users you have to sign up here

Click on the + button on the left Nav bar , Select->Repository

Follow here to complete the process and have your Android project uploaded to your just created repo.

Yea!. back to the business of the day.

Enable Bitbucket Pipeline

To start using Bitbucket Pipeline, you simply need to go to your repository, and under the Pipeline menu , choose a language template. In this case Java(Gradle), then click on commit this will automatically create a YAML file to start with under your master branch.

Configure Docker

Here you’ll need a Docker image to to build your app. It has to include your Android build environment to be able to compile it. To simplify it, Uber dev team created one for this purpose that you can use here.

For those familiar with docker, you can go ahead and create your own docker light image. incase you don’t need all packages included in the Uber image.

But for this post , we will be using the Uber image.

# — — — # You can specify a custom docker image from Docker Hub as your build environment.image: uber/android-build-environment:latestpipelines:  default:    — step:      script: # Modify the commands below to build your repository.        — echo “Start default step”        — ./gradlew assembleDebug

NOTE:

You build will fail if the YAML file is not right indented . So help handle this use Bitbuck-pipeline validator

First, I specify the image that is going to be used to build the app. Then by default, for any branches, it will execute commands. Here I build a debug APK using Gradle wrapper. Our continuous integration is ready!

Now we will create a build.sh file to house our reusable script. Make sure you give it the right permissions.

#!/bin/sh

# Add Android SDK license in a default file
mkdir "${ANDROID_HOME}/licenses" || true
echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > $ANDROID_HOME/licenses/android-sdk-license
echo "d56f5187479451eabf01fb78af6dfcb131a6481e" > $ANDROID_HOME/licenses/android-sdk-license

# Build the app
./gradlew assembleDebug

To give the file the permission to execute . Run this on your terminal(Make sure your currently in the your project root folder)

git update-index --chmod=+x build.sh

Then check to see if it has 0755

git ls-files --stage100755 58b61dd2872df1ba7a0ad96f81e801a788c46502 0 build.sh

Update the Bitbucket-pipeline.yml file to point to the build.sh file. This file contains your Android SDK license

# — — — # You can specify a custom docker image from Docker Hub as your build environment. 
image: uber/android-build-environment:latest
pipelines:
default: — step: script: # Modify the commands below to build your repository.
- unset ANDROID_NDK_HOME # To unset the NDK env if not needed
— echo “Start default step”
— ./build.sh
- echo "Amazing"

Coooool!!!

Our Continuous Integration build and test is Successful

once built and tested, for a specific branch, you can actually deploy it somewhere. That’s what we’re going to do with HockeyApp in the Part 2 of this post.

Thank you for reading. Please comment in case of any difficulty.

I will be glad to help.

--

--

Nsikak Thompson
DroidPlate

Android developer | Technical writer | Community Enthusiast