Basic Implementation of CI and CD in Android Development

CI and CD is a software development practice that most mobile developers in team projects use daily, however, most often version control practices (or git branching strategy) as well as automated testing/deployment already installed and only minor changes would be needed if anything. On the other hand, setting up our own CI and CD pipeline when working on individual or personal projects may seem more useful if not with learning motive or client requirement.

As a result, many mobile developers may feel that CI and CD are outside their area of ​​expertise, and may do so without the use of mobile DevOps platforms, but mobile CI and CD are easier than ever through the use of automation. Has not been. these platforms.

This article will not focus on CI and CD as a concept, but on an overview of the implementation of CI and CD via a mobile DevOps platform, using its simplicity but many configurable features.

CI (Continuous Integration)

When we talk about CI we regularly refer to integrating or pushing code into a shared code repository, and the team’s shared repository of changes to detect any issues before it is merged into the shared repository. against automatically running tests.

CD (Continuous Delivery/Deployment)

As far as CD is concerned in the context of mobile app development, we want to build our apps automatically and send them to QA, Clients, Testers…

DevOps Platform

There are very popular source control platforms like GitHub and Gitlab, and they both provide their own CI/CD pipeline integration. These are certainly viable solutions, especially when your project is already being hosted there, but due to their multi-purpose and multi-platform nature, they are hard to understand when it comes to the only aspect of mobile continuous integration and development. it happens.

The end product of a CI/CD configuration file is a YML file that contains instructions to be performed by an external machine. Mobile DevOps platforms allow us to use their interfaces and a wide range of features to optimize our pipeline in a secure way, as it generates the said YML file without editing any lines of code in the file. Similarly, modifying the YML manually will also update the UI steps we see in the workflow. It also provides build reports and information to the user more clearly, as the platform is completely focused on CI/CD integration.

There are some general concepts in CI/CD and more specifically DevOps platforms that should be explained:

Workflow – The main tool we will use to optimize automation. A workflow is a set of steps that the platform performs for us to implement the CI/CD pipeline. These may include building, testing or deploying an app.

Step – Steps are the various actions that our platform can perform inside a workflow, these can include Git repository action, running build, deploying APK, modifying Gradle file, or simply a script…etc. There are many possibilities.

triggers – these are the conditions trigger a workflow. These will most likely be related to push and merge requests from one branch to another.

Environment Variables – Like your standard environment variables, these variables can be stored in the project’s location so that they are widely available within the workflow. Examples can include APK directories, package names, app modules, or variants.

Mystery – Similar to environment variables, these may be required at some stage in the workflow, but secrets contain sensitive information secured, for example, tokens to access the Play Store API.

code signing – This will include all files required when releasing, such as keystore files, their aliases and passwords. Bitriz will safely store and securely handle these for you.

yml file – This is the configuration file that you set through the platform’s interface. It is always accessible for you to read and edit. This will act as an instruction guide for the machine running the pipeline. This file should be stored in the app repository (Bitrise can manage it for you). This is useful if you ever run into CI configuration issues as you can easily go back to a previous version and update the YML file to BitRise.

Introducing Bitrise

There are many DevOps platforms out there, but Bitrise is a mobile-first provider and arguably one of the simplest yet capable platforms. Plus, you get some free credits for setting up your pipeline and running some builds. You can find Bitrise at the top of many Mobile DevOps Platform lists.

For almost every Android CI/CD action you want to run, the Bitrise docs have a template for that workflow, explaining what steps you should add and why. Some steps may be considered boilerplate as they may be needed in a workflow regardless of platform or target e.g.: connecting to our VCS, cloning the project repository, pulling/cache from BitRise to speed up build times. Pushing, or deploying the build results back to bitrate. However, most other phases will be defined by the target and the platform.

CI and CD in practice

To integrate pipelines we need to define version control first or git branching strategy. Next, we’ll describe a general sample* strategy that will help us define our workflows.

This will include the following branches and their roles:

  • Development – This is the base branch with a stable shared codebase for the devs in the team. Every time we want to add code we checkout this branch and do a push or pull request to revert the changes DevelopmentTrigger unit tests as well as UI tests which, if passed, will allow MR or PUSH to succeed.
  • scaffolding – We will merge when we want our code to pass a QA check Development In scaffolding, QA should only use this branch to make their tests pass. This step can generate an unsigned APK build to be deployed on platforms such as Firebase for testers and/or clients to test. No testing is needed in this workflow as we will be repeating the same tests against the same codebase Development workflow.
  • release – When our app is ready to deploy we can merge scaffolding In release, This can trigger a release on the Play Store, but even though some people prefer to manually update the app and skip this trigger, you can also use it to release on an alpha or beta channel, if necessary. Not production.

*This strategy is just an example and not a best practice, it provides a good foundation and understanding for implementing CI/CD through a mobile DevOps platform. The best or most optimal strategy can depend on many factors and will vary from project to project.

our workflow

Next, we’ll see how in 3 different workflows Development,scaffolding,release What will the VC strategy described above look like, and how are they triggered.

Development Workflow:

Role → Merge to this branch means adding changes to the code that need to pass tests before merging, to make sure the new code doesn’t break anything.

trigger → a . Pushing or creating a merge request from development/feature_branch (or any other) Development branch.

Specific Steps → This workflow will run all the Android steps required to run Unit Tests and UI Tests if we have any. For this we can read the Bitrise docs and find out what steps we need and configure them accordingly. For example, when testing for UI tests we might need a AVD Manager step, and if we are using an emulator then we need a . is required wait for android emulator Step.

Staging Workflow:

Role → Merging to this branch may mean that the APK must be made available to a group of interest, such as QA, or to a client.

trigger → push scaffolding branch

Specific Steps → This workflow does not include any test phases, as no changes have been made to the code from the codebase Development, This workflow is characterized by an Android build phase that generates an unsigned APK and another phase that distributes it to Firebase.

We’ve also added steps to automatically modify the version code and versionname of our app to display some interesting features. To do this we need to run a script that will modify the Gradle file dynamically, however, this requires the branch name to contain the desired version name, and the versioncode to be updated only to the bitaris build number. Therefore, it has clear limits.

AX6xNFtBeaS6ur VMZVkIpsMEqEyZPGIg5YIq PapsEalsU0SCfB 3WzEKouTsl3q6zBW3Fnooa4cqif Hg9ZWyFxo S1r Z5YoKb39DVdzg2GHiPAYPkBS1GZHTPAY

Release workflow:

Role → Merging in this branch means that one APK should be deployed on playstore, one channel(s).

trigger → push release branch

Specific Steps → This workflow is characterized by adding an Android sign step to the build (this will require a keystore JKS file and app signing information such as alias keys and passwords) and another step to distribute to the Play Store (play store console Requires a service account) set up, as well as a file with release notes, if desired, and other specifications such as channels, apks or bundles… etc.)


set trigger

Now that we’ve defined our workflows, we can configure triggers, which means specifying which actions will trigger each workflow. Bitrise has a tab for us to specify these actions easily.

for Development workflow, we set up a trigger for pull requests (or push), in which we say any branch creating a PR Development will start Development (called development_test In the screenshot) Workflow:

The next time we create a PR, our VC website will give a message indicating that a bitrise pipeline is underway. It will show green check or error depending on the success of the build.

9LDZBxWNt22cQDi66j5iXtbWsSng ql0qPMA3bgPhWQqlHGoMJn28aqhptVo JuO RffiyZzS uMYs4RP0N3SKOFqP kKpoatpOPXOtSbRUd8J2d5WrluLl Om0R60okNWk2eaVP1d3p8AwOg4J13APM72ofkj3SrMu5CnbFolTgCVjT5WlXO7gM3zlPCQ

for scaffolding (called staging_deployment_firebase_apk in the screenshot) and release (called release_deploy In the screenshot) workflow, we have similar triggers. Both will be triggered when a push action occurs in their respective branches:


all set!

Once we’ve defined the workflows and triggers, we’ve essentially created our pipelines, and all we need to do is respect the branching strategy to properly implement CI/CD.

We didn’t dive into the details of every step configuration and platform feature to keep it short and sweet, but hopefully this article will provide some insight into how simple CI/CD can look in an Android project and the capabilities of the mobile DevOps platform.

Leave a Comment