Categories
Technology

Automate and deploy Android and iOS Builds using Fastlane and Self-Hosted Runners

Automate and deploy Android and iOS Builds using Fastlane and Self-Hosted Runners

Introduction :

Why automate Android and iOS builds?

Automating Android and iOS builds focuses on the build and deployment steps in the Software Development Life Cycle (SDLC) to save time. By automating these processes, we reduce manual intervention, minimize errors, and ensure faster and more consistent delivery of application updates.

Continuous Integration and Continuous Deployment (CI/CD) pipelines are crucial in modern mobile app development. They ensure that code changes are automatically built, tested, and deployed, reducing manual effort and the risk of errors.

Introduction to CI/CD Pipeline

Continuous Integration (CI) and Continuous Delivery (CD) are practices that enable development teams to deliver code changes more frequently and reliably.

Continuous Integration (CI): Developers merge their code changes into a central repository. Automated builds and tests are run to ensure that the new code does not introduce any bugs or break existing functionality.

Continuous Delivery (CD): Once code passes CI, it is automatically deployed to a staging environment. From there, it can be released to production with a manual approval step.

Tools: Jenkins, GitHub Actions, GitLab CI, CircleCI, Travis CI.

Benefits of a CI/CD Pipeline

  • Faster Development Cycles: Automated processes reduce the time required for code integration and deployment.
  • Improved Code Quality: Continuous testing ensures that code changes do not introduce new bugs or regressions.
  • Enhanced Collaboration: Teams can collaborate more effectively with a streamlined workflow.
  • Reduced Manual Effort: Automation minimizes manual intervention, reducing human error and freeing up developer time for more critical tasks.

The primary goal is to ensure that code changes are integrated and delivered to production rapidly and safely.

Introduction to Self-Hosted Runners

Self-hosted runners are machines that you manage and maintain to run GitHub Actions workflows. Unlike GitHub-hosted runners, which are managed by GitHub, self-hosted runners provide more control over the hardware, operating system, and software environment.

Step-by-Step Guide

  • Create a Runner:     
    a. Go to your repository on GitHub.
    b. Navigate to Settings > Actions > Runners > New self-hosted runner.
    c. Choose the operating system for your runner (Linux, macOS, or Windows).
  •  Download and Configure the Runner: Follow the provided steps to setup self-       hosted runners.

Introduction to Fastlane

  • Fastlane is an open-source platform designed to streamline the process of building, testing, and releasing mobile applications for iOS and Android. It automates many repetitive tasks in the app development lifecycle, making it easier and faster for developers to deploy their apps.

Setting Up Fastlane for Android and iOS

  • Installing Fastlane :  
                              Fastlane can be installed in multiple ways. The preferred method is with Bundler. Fastlane can also be installed directly through Homebrew (if on macOS). It is possible to use macOS’s system Ruby, but it’s not recommended, as it can be hard to manage dependencies and cause conflicts.
  • Setting up Fastlane :   
         Navigate your terminal to your project and run ‘Fastlane init’ inside android and iOS directory.

        This will create Fastlane folder inside our project android and iOS directory.

Deploy Android and iOS Builds to Firebase

Android fastlane code

iOS fastlane code

Integrating Fastlane with GitHub Actions

Integrating Fastlane with CI/CD (Github Actions) pipelines is essential for automating the build, test, and deployment processes for mobile applications. This integration ensures that each code change is automatically built, tested, and deployed, improving efficiency and reducing the risk of human errors.

Explanation:

  • Trigger: The pipeline runs on push events to the main branch and on pull requests
    Or on Workflow_dispatch on manual trigger.
  • Jobs:
    a. Build: Checks out the code, sets up the JDK, caches Gradle dependencies, builds the app, runs unit tests, and uploads the APK.
    b. Deploy: Deploys the apk or aab to Firebase App Distribution/Playstore/Appstore (after the build job succeeds).

 Workflow in Github Actions

Common Issues and Troubleshooting