Building Android Apps using GitHub actions


Github actions is an excellant choice for producing automated Android builds and for replacing your in-house CI solution. Here at P4 we have recently moved to Github actions as our preferred build/CI server and to push successful builds to Appstage for installation by our clients.

Our workflow has a number of steps:-

  • Checkout the source

  • Setup the JDK ready for builds

  • Run the unit tests

  • Build the apk

  • Tag the build

  • Upload as an artifact

  • Push to Appstage

Lets go through each step in turn. (The full script is at the bottom of this post)

Checkout the source

We use the latest Ubuntu OS for Android builds and first checkout the source using default setup.

Setup the JDK ready for builds

Set up the JDK with the required Java runtime.

Run the unit tests

We have to give permission for gradlew to execute in our build environment before calling gradlew to run the unit tests (and build the apk).

Build the apk

Note that we automatically update the build number as part of gradle script and use this version in the filename of the output apk. The last step is to get this version and set it as a enviroment variable in order to use it later in the workflow.

Tag the build

As we are advocating continious delivery (via Appstage) every build of the app could potentially go out of the door we prefer to tag every build. As the Github action itself is performing the build it doesn’t by default have a user configured so we do this just before we perform the tag. Note we use the version variable set in the previous build step as part of the version tag and message.

Upload as an artifact

If anything goes wrong with the upload to Appstage or if Appstage becomes unavailable we add the new apk to the build artifacts so it is available in Github.

Push to Appstage

The last step is to push the newly build apk to our Appstage project ‘Live builds’ page using the custom Appstage action. We first delete the old apk and then upload the new one.

The full script

Here is the full script that checks out, builds, tags, artifacts and uploads the Android apk to Appstage:-

Next
Next

WebAuthn - a better alternative to passwords?