CI/CD for Mobile App | Auto build Mobile App with CodeMagic

Tram Ho

What is CI/CD?

The concept of CI (Continuous Integration) or CD (Continuous Delivery) is probably no longer strange to the devs. Literally, it is the process of integrating and using the software’s continuous working and automation tools into the product’s development lifecycle. In a rustic way, this is the process of automatically building, testing, deploying the web (for FE/BE) or building the app, deploying the app to the app market (for Mobile App) with just one button (or trigger on it). Git’s on push action). Nowadays, CI CD becomes a natural thing to have in the software development process. CI-CD-la-gi-1.png

Purpose and limitations

As mentioned above, CI/CD is applied a lot to the software development automation process. Or we can build our own installation for Android / iOS from open source projects without knowledge of Mobile programming, for example. This is quite good for non-tech brothers because there are many cool open-source mobile projects (Youtube Vanced is an example), after building an apk or ipa file (using AltStore to install on macOS, which If everyone is interested, I will post another post later) install it directly on the device.
The biggest drawback is that using a lot will cost money. For each CI/CD service provider, the fee will be different. If you use CodeMagic, you will get 150 hours per month for free, which is pretty cool. Here is a small tip is to use 150 hours, then create another account to use it for free
The second limitation is that it is quite difficult to configure with too many complex projects (multiple environments, …)


Introduction to CodeMagic

As the title of the article, we will only go into CI/CD on Mobile App (or because I don’t know how to do FE/BE). Currently, there are many providers that support this, such as Github Action, Bitrise, Gilab CLI, … (if people are interested, I will post another post). However, in this article we will use CodeMagic. Surely, many Flutter coders will probably find this name familiar because this is a place to share a lot of detailed blogs/guides about Mobile App, you can refer to it here.

Register and configure Source Code

To use it, for sure, we must register an account here . Please allow me to skip this step

After logging in, we proceed to add the application from the Git repo (Github, Gitlab, Bitbucket…). Here I will demo add Github repo. Select Add application , then select Github and select Github integration to grant CodeMagic read github repo permission
image.png Note that here only my repos can be added, so if the repo is not mine, you can fork it quickly.
Next, select the project type. Here I am trying to build a Flutter application, so I will choose Flutter and when successfully added, I will have the following results image.png


Next comes the most important part of the process. Here we will have 2 ways to configure

Configuration using Work Flow Editor

image.png This is a pretty simple way to configure instant noodles. As you can see in the image above, we just need to tick and tick the following items: Build for Platforms: Will build the installation file for which platforms Run build on: What device the source code will be built on . Here by default we will build on Mac Mini M1, the remaining options must be loaded for the first time (add banking info) to choose from, including Linux, MacOS and Window.
Build trigger: Trigger to act when the application will be built. This depends on the nature of the work flow, if deployed to a testing environment, it will usually trigger on push of the dev or staging branch. If configured to deploy, it will trigger on the master branch of the repo. image.png Environment variables: Add env variables to the build
Build: Select Flutter, XCode, CocoaPods version, choose build mode (debug, release or profile), Android output format (apk or aab), parameters passed during build image.png Distribution: Configure keystore, sign app to publish image.png Notification: Notification channel, can be notified via email or Slack when the build is complete (here can configure the webhook to fire notifications)

Configuration using .yaml . file

With some projects with more complex configuration, we need to configure it with the yaml file. Similar to the configuration above, using the .yaml file will also have the same items but at a more advantage level.
The following is a workflow with a sample .yaml file to run the build to the Android installation file.

As you can see, it is quite cumbersome to configure for those who do not have programming knowledge, so I do not recommend this way very much.


After the build is successful, a notification will be sent. The installation file will be included in the email or build history, you just need to download the file and install it directly (for Android) or through a little other trick (for iOS).

Above, I have just basic guide to create a workflow to build files automatically, in the next article I will guide you on sign keystore, auto deploy to CHPlay every time you build. Click upvote if you find it interesting to support me

Share the news now

Source : Viblo