From Manual to Automated: Transforming Your Flutter App with fastlane

Image Source:

Introduction

In the fast-paced world of mobile app development, delivering updates and new-features efficiently is crucial. But still many developers rely on manual release process of their apps to Google Play Store / App Store. This traditional manual process of release is prone to human error and its time consuming, where they have to build apps, manage code signing and handling app store submission.

This is where fastlane comes into picture*. fastlane* is the easiest way to automate beta deployments and releases for your iOS and Android apps 🚀.It handles all tedious tasks, like generating screenshots, dealing with code signing, and releasing your application.

History and Evolution

Initial release of fastlane was in 2014 by Felix Krause, which was focused on code signing and uploading apps to App Store (iOS).

  1. By 2015 they extended their support to Android and its release process by expanding its capabilities like Google Play Store Submission and gradle for Android builds.
  2. During the years 2016-2018:  fastlane introduced several tools to help with the release process like:
    • snapshot: Used to automate taking app screenshots for App Store.
    • screengrab: Used to automate taking app screenshots for Play Store.
    • match: A tool for managing code signing.
  3. During the years 2018-2021: community growth and ecosystem updation where they extended their services which allowed to integrate with Slack, Jira and Firebase. Also they improved their documentations, providing guides, tutorials and examples which would help developers integrate fastlane with their existing workflows.
  4. 2021 - Present: Support provided to integrate with CI/CD platforms like GitHub Actions, GitLab CI, Circle CI, Bitrise, Jenkins, Travis CI and Codemagic. They have already provided support to cross platform technologies like Flutter, React Native and NativeScript.

Problem Statement

Traditional mobile app development and deployment often includes manual processes, prone to human errors and heavy time consumptions which is inefficient in a way.These challenges highlights the need for an automation process where fastlane comes in handy due to its automation of beta deployments, production deployments also its effectiveness with CI/CD pipelines.

Technology Overview

Install fastlane:

brew install fastlane

Setting up fastlane:

Navigate your terminal to your project's directory and run

fastlane init

This will create the Fastfile configuration file

Configuring FastFile:

This is where we define lanes which are custom workflows that are required to automate various tasks.

iOS FastFile example:

# ios/fastlane/Fastfile

default_platform(:ios)

platform :ios do
  desc "Build and push a new beta build to TestFlight"
  lane :beta do
    match(type: "appstore") # Code signing
    build_app(scheme: "MyApp") # Build the app
    upload_to_testflight # Upload to TestFlight
  end

  desc "Build and release a new version to the App Store"
  lane :release do
    match(type: "appstore") # Code signing
    build_app(scheme: "MyApp") # Build the app
    upload_to_app_store # Upload to the App Store
  end
  
  desc "Build shorebird release build"
  lane :release_shorebird do
	  shorebird_release(platform: "ios")
	  upload_to_testflight
	end
	
	desc "Build shorebird patch"
	lane :patch_shorebird do
	  shorebird_patch(platform: "ios")
	end

  desc "Run tests"
  lane :test do
    run_tests(scheme: "MyAppTests")
  end
end

Android FastFile

# android/fastlane/Fastfile

default_platform(:android)

platform :android do
  desc "Build and push a new beta build to Google Play"
  lane :beta do
    gradle(task: "assemble", build_type: "Release") # Build the app
    supply(track: "beta") # Upload to Google Play Beta
  end

  desc "Build and release a new version to Google Play"
  lane :release do
    gradle(task: "assemble", build_type: "Release") # Build the app
    supply(track: "production") # Upload to Google Play Production
  end
  
  desc "Run tests"
  lane :test do
    gradle(task: "test")
  end
end


GitHub Actions Workflow File
:

This file is necessary to integrate fastlane within your existing CI/CD pipeline.

name: Fastlane CI/CD

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  ios:
    name: Build and Deploy iOS App
    runs-on: macos-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: '3.1' # Specify the Ruby version to use

      - name: Install dependencies
        run: |
          gem install fastlane
          bundle install

      - name: Run Fastlane beta lane
        run: fastlane beta
        env:
          APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }} # Set up as a secret in GitHub
          
      - name: Run Fastlane release lane
        run: fastlane release
        env:
          APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }} # Set up as a secret in GitHub
          
      - name: Run Fastlane Shorebird release lane
        run: fastlane release_shorebird
        env:
          APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }} # Set up as a secret in GitHub
          
      - name: Run Fastlane Shorebird patch lane
        run: fastlane patch_shorebird
        env:
          APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }} # Set up as a secret in GitHub

  android:
    name: Build and Deploy Android App
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: '3.1' # Specify the Ruby version to use

      - name: Install dependencies
        run: |
          gem install fastlane
          bundle install

      - name: Run Fastlane beta lane
        run: fastlane beta
        env:
          GOOGLE_PLAY_JSON_KEY: ${{ secrets.GOOGLE_PLAY_JSON_KEY }} # Set up as a secret in GitHub
          
      - name: Run Fastlane release lane
        run: fastlane release
        env:
          GOOGLE_PLAY_JSON_KEY: ${{ secrets.GOOGLE_PLAY_JSON_KEY }} # Set up as a secret in GitHub


By doing this we can automate our entire development and deployment process, where fastlane is primarily used for tasks related to Continuous Deployment (CD) and Continuous Delivery (CD) in mobile app development.

Challenges and Limitations

MacOS requirement for iOS builds:Since building an iOS app require macOS environment due to Xcode dependencies and even though GitHub Actions provide macOS runner which can be high in demand leading to longer Queue time and costs more than a linux runners.

Code signing complexity (iOS) and Android Signing key management.

Environment Specific configurations would require to handle them separately which would be tedious.

Security: Ensuring the security of the pipeline and the code is crucial to prevent vulnerabilities. Even managing secret keys without any leaks is critical.

Tool Integration: Integrating various tools and technologies can be challenging and may require custom solutions.

Build time limits imposed by GitHub Actions.

Future Outlook and Conclusion

The future of Fastlane in conjunction with GitHub Actions looks bright, with continuous improvements expected in automation, security, cross-platform support, and cloud-native capabilities. As these tools evolve, they will likely become even more powerful, making them indispensable for mobile app developers, especially those working with Flutter. By staying updated of these trends, developers can ensure they are leveraging the best tools and practices to maintain efficient, secure, and scalable CI/CD pipelines.

References

[1]
[2]
[3]
[4]
[5]
[6]
[7]

Contents

Share

Written By

James Mathew

Flutter Developer

Versatile Flutter developer skilled in creating exceptional user experiences for web, mobile applications, and cross-platform development. My proficiency spans the spectrum, ensuring cohesive and polished results across diverse platforms. Crafting seamless and engaging interfaces isn't just a job for me – it's my dedication and passion

Contact Us

We specialize in product development, launching new ventures, and providing Digital Transformation (DX) support. Feel free to contact us to start a conversation.