December, 2021
Github Workflows in Action for Android Apps
SHARE THIS

We all know manual build-sharing can be a huge hassle throughout the process. The android studio takes a lot of time to generate apk or .aab files and the situation becomes particularly exacerbated if you are working on a large project comprising of multiple modules.

What’s more, this process is further complicated by the fact that you need to dispatch the generated build to QA teams by uploading it manually via email, Slack, Microsoft Teams, Firebase or any other build-sharing or communications platform. And God-forbid if the QA testers suggest a single change. Writing from personal experience, there can be times when multiple builds need to be generated in a single day – well, there goes all your development time spent on generating these builds.   

However, effective CI/CD pipelines can readily change that. It allows us to conveniently automate the entire process mentioned above while saving us loads of time – and this blog is going to show you the best method for that.

Some Tools to Implement CI/CD Pipelines

There are quite a few tools around which you may use for implementing CI/CD pipelines but some of the most common ones are mentioned below:

  • Jenkins
  • Circle Ci
  • Github Actions

So, what’s the difference, one may ask? The difference is that not all CI/CD implementation tools are created equal. I personally prefer GitHub Actions—and here’s why you should too:  

 

Jenkins vs GitHub Actions

Essentially, Jenkins helps us perform the same tasks that GitHub Actions does. Like GitHub Actions, it is also free and facilitates CI/CD implementation in software development. In itself, it is a viable option for the task at hand but following are some of the challenges that one may face while using Jenkins:

  • It is inconsistent with concurrent builds.
  • It is dependent on multiple plugins.
  • The plugins need to be kept updated to smoothly run CI/CD pipelines and errors will arise whenever they go out of date.
  • 3rd party plugins pose a significant security risk.

In contrast, using GitHub Actions you don’t need to worry about the security and privacy of your source code. What sets GitHub Actions apart from Jenkins is the fact that it is maintained by GitHub itself. This also means that you don’t need to worry about scalability and infrastructure when dealing with it.

In addition, GitHub Actions supports several languages and frameworks, and these are written in YAML. Therefore, they can be edited, reused, shared, and forked just like code.

CircleCI vs Github Actions

CircleCI is quite similar to Jenkins and GitHub Actions, but it also poses a number of issues that GitHub Actions does not. You need to do the following with it:

  • Connect your repository to CircleCI.
  • Write your pipeline configuration script.
  • Run your pipeline on CircleCI’s servers.

All of the above means that you need to manage your CI/CD pipeline on CircleCI’s platform instead of GitHub – an additional step that is not really needed. It is for these reasons that I will generally choose GitHub Actions over CircleCI and Jenkins.

Why Visual Studio App Center?

Visual Studio App Center also makes life significantly easier by bringing together several services that are generally used by the mobile developers. These include the ability to build, test, distribute, monitor, and diagnose (among a host of other things) at a single place on the cloud. Along with GitHub Actions, it will make your life significantly easier. That said, you may use nearly the same method (described below) to create CI/CD pipelines for deploying APK files on Slack, Diawi and Firebase as well.

So…how to implement CI/CD pipeline using GitHub Actions to deploy an android application on Visual Studio App Center? Read on to find out. While this blog contains steps for deploying debug APK files on App Center, you may do the same for signed APK files or AAB files as well. For that, you will need to add your keystore to GitHub…but that would require a blog of its own – one that you may find on Analytics Blog quite soon as well. 

Deploying Android App on Visual Studio App Center Using GitHub Actions

Upload Application Code to GitHub Repository

First, you will need to upload your application code to GitHub repository. You must ensure gradlew, gradlew.bat and gradle-wrapper.jar are also uploaded on the GitHub repository or you will face errors while trying to run GitHub Actions for CI/CD pipeline implementation.

Create yml File

Once you have uploaded the application code to the GitHub repository, you will need to create yml file in .github/workflows/main.yml inside your respository.

By default, you will not be able to see .github/workflows/main.yml file.

Create New Android Application & Generate API Token

Once you have created the yml file, you need to open the Visual Studio App Center (https://appcenter.ms/ ) and create a new android application. In the new application, you will need to go the Applications Setting and generate an API Token. Keep the token safe for later use.

Create Actions Secrets

Now navigate to your GitHub repository settings and create secrets as shown in the image below:

In APP_CENTER_APP_NAME you need to enter app name in the following pattern: {Your APP Center UserName}/{APP Center App Name} and in APP_CENTER_TOKEN you need to copy paste the API token you had generated previously.

Copy Code to yml File

Once you have created Action Secrets, open the yml file you had created above and copy-paste the code below:

The code may be copied from here: https://gist.github.com/DaaniDev/b2ba4e68f1db92561a8d120d81c0d4fc

Once you have copied the code to the yml file then all you need to do is run the GitHub workflow. And you are all set! You just saved yourself loads of time on APK deployment –you may spend all that free time on development…or maybe go grab a cup of coffee.

Picture of Muhammad Danish

Muhammad Danish

Danish works as Senior Software Engineer (Android) at TenX.