Android Template With Fastlane and Github Actions

Skip the setup and start building your next Android project

Asad Mansoor
The Startup
5 min readJan 27, 2020

--

Setting up an Android project can be a tedious task. One must download the correct set of tools, configure a continuous integration and continuous deployment (CI/CD) pipeline and share the standards on how to contribute to the project on GitHub. In this blog post, I’ll discuss how a template can help automate the process of setting up an Android repository.

GitHub Template

A GitHub template is a repository that contains files and directories that can be imported to a new repository upon creation. This is essential to organizations that wish to share the same development practices across various projects. For example, a template for mobile applications can contain pre-set Fastlane dependencies and GitHub Actions workflows to start building and deploying from the very first commit. Fastlane is a tool that helps automate tasks for building, testing and deploying mobile applications, whereas GitHub Actions allows the creation of CI/CD workflows within the GitHub repository. Although the tools that a repository needs may vary across teams and organizations, it is crucial that projects are set up and managed through some standards to enhance the developer experience, increase feedback loop and eliminate any steep learning curves. With a template, teams can come together to establish a standard and allow developers to start creating new repositories based on that template.

Link to Android template.

Creating a repository from a template

Visit the template and click on Use this template.

Configure the options of the owner, repository name, description and the visibility of the repository. Once all of the required information is provided, click on Create repository from template.

Voila. A new repository will be created under your account with the following files and directories that were included in the template. You can now start building your project.

Fastlane

Fastlane is a tool to automate any tedious tasks in building, testing and deploying mobile applications. In this template, the fastlane template is set up to run specific Gradle commands locally and on the GitHub Actions pipeline.

Here are the following fastlane actions specified in the template.

Android compile

# Compile debug and test sources$ fastlane android compile

Android lint

# Execute lint and creates a HTML report$ fastlane android lint

Android assemble

# Assemble debug source and test APKs$ fastlane android assemble

Android unit test

# Execute unit test$ fastlane android unit_test

Android instrumentation test

# Execute instrumentation test on Emulator$ fastlane android instrumentation_test

The advantage of using fastlane allow teams to configure the lanes based on the desired needs of the project. With lanes defined, developers can execute the following operations locally or on the GitHub Actions pipeline.

GitHub Actions

GitHub Actions allows the creation of custom workflows within the GitHub repository. These custom workflows can automate specific tasks to build out continuous integration and continuous deployment pipeline. In this template, the CI pipeline is set to validate the new changes through the following stages of compiling, performing lint analysis, assembling APKs and performing unit and instrumentation tests.

Dividing the various jobs into stages allow developers to get fast feedback without using a lot of resources. For example, if the changes fail to compile the application, the pipeline would alert the developer and would not carry on with the rest of the pipeline.

Once a pull request is open, developers can perform code review while GitHub Actions performs the following checks defined in the PR Pipeline Workflow, a custom workflow in the template to run only on pull requests.

Workflows are defined as yml files and placed under the .github/workflows/ directory. In the workflow, one must specify when to run the workflow, either on pull requests, branches or scheduled instance, along with the operations it must carry out. In the PR Pipeline Workflow, the following pipeline only runs on pull requests to the master branch.

An example of the compile job can be found below.

name: PR Pipeline Workflow # Execute PR Pipeline Workflow on pull requests to master
on:
pull_request:
branches:
- master
jobs:
################################
# Compile Job:
# Install dependencies and compile debug and test source
############################
compile:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2

- name: Set up Ruby 2.6
uses: actions/setup-ruby@v1
with:
ruby-version: 2.6.x

- name: Install Dependencies
run: gem install bundler && bundle install

- name: Run Fastlane Compile Lane
run: fastlane compile
...

Issue Template

With this template, we have the following foundation for Fastlane and GitHub Actions. Building software applications requires a team effort. In order to work efficiently, teams need to follow a specific standard when creating issues and pull requests. With a specific format, it would be easier to share the issue as well as have the correct set of information to resolve the issue efficiently. The repository template also contains templates on creating issues and pull requests as shown below.

Issues

Issue templates can be found in the .github/ISSUE_TEMPLATE directory that contains the specific design for the following types of issues.

For instance, in order to create a new Bug Report, the following template will be shown to the reporter to fill out with the required information.

Pull requests

Template for pull request can be found in the .github directory. When a new pull request is being created, the following template is used by the developer to share the context of the changes being merged.

Android Template

The following template contains the setup of Fastlane, GitHub Actions and issue and pull request template, ready to jumpstart Android projects. Feel free to create your next Android project from this template or start building your own template for your personal projects or organization.

Thank you.

--

--