DEV Community

مصعب يوسف
مصعب يوسف

Posted on Originally published at Medium

Ultimate Step-by-Step Guide to CI/CD with Fastlane in Flutter (Mac & Windows)

Ultimate Step-by-Step Guide to CI/CD with Fastlane in Flutter (Mac & Windows)

Setting up CI/CD (Continuous Integration and Continuous Deployment) is a must for modern Flutter developers who want to streamline app development, testing, and delivery. Manual builds and uploads are tedious, error-prone, and time-consuming. That’s where Fastlane comes in — an incredibly powerful automation tool that simplifies building, testing, and releasing Flutter apps for both Android and iOS platforms.

In this extended guide, I’ll walk you through setting up Fastlane for your Flutter projects on Mac (for both iOS and Android) and Windows (for Android builds), using real-world examples and production-ready configurations.

What is Fastlane and Why Use It?

Fastlane is an open-source automation tool designed specifically for mobile developers. It allows you to automate repetitive tasks such as:

  • Building and archiving your apps
  • Running tests across devices and platforms
  • Managing code signing and provisioning profiles
  • Publishing apps to the Google Play Store and Apple App Store
  • Distributing pre-release builds to testers with services like TestFlight or Firebase App Distribution
  • Automating versioning, screenshots, changelogs, and more

By integrating Fastlane into your development workflow, you can ensure consistent builds, reduce human error, and speed up your delivery process significantly.

Requirements Breakdown

Before diving in, ensure your environment is ready:

Mac Requirements (for Android & iOS)

  • Latest version of Xcode installed (for iOS builds)
  • Flutter SDK properly installed
  • Android Studio with SDK & command-line tools
  • Homebrew package manager (optional, but recommended)
  • Ruby & RubyGems for Fastlane installation
  • Valid Apple Developer Account for iOS deployment
  • Google Play Console access for Android releases

Windows Requirements (for Android only)

  • Flutter SDK installed and configured
  • Android Studio with SDK & command-line tools
  • Git Bash or terminal for command execution
  • Ruby & RubyGems for installing Fastlane
  • Google Play Console access for uploading builds

Note: iOS builds can only be performed on macOS due to Apple’s restrictions.

Step-by-Step Setup for Android CI/CD (Windows & Mac)

1. Install Fastlane

On both Mac and Windows:

On Windows:

  1. Download RubyInstaller: https://rubyinstaller.org/
  2. During installation, check Add Ruby to PATH.
  3. After installation, open Git Bash or PowerShell and run

-NV speeds up the installation process by disabling documentation downloads.

gem install fastlane -NV
Enter fullscreen mode Exit fullscreen mode

Alternatively, on Mac:

brew install fastlane
Enter fullscreen mode Exit fullscreen mode

Verify installation:

fastlane --version
Enter fullscreen mode Exit fullscreen mode

2. Navigate to Your Flutter Android Directory

cd path/to/your/flutter/project/android
Enter fullscreen mode Exit fullscreen mode

3. Initialize Fastlane

fastlane init
Enter fullscreen mode Exit fullscreen mode

Follow the setup prompts:

  • Select “Manual setup”
  • Choose “Android”
  • You’ll create lanes for tasks like building, testing, and deploying

4. Example Fastfile for Android Automation

-Simplified code

default_platform(:android)

platform :android do
  desc "Clean project and build release AAB"
  lane :build_release do
    gradle(task: "clean")
    gradle(task: "bundle", build_type: "Release")
  end
  desc "Deploy to Internal Testing Track"
  lane :deploy_internal do
    build_release
    upload_to_play_store(track: 'internal')
  end
end
Enter fullscreen mode Exit fullscreen mode

-Professional code

default_platform(:android)

platform :android do
  desc "Build Flutter AppBundle (AAB) for release"
  lane :build_aab_release do
    UI.message("Cleaning Flutter project...")
    sh "flutter clean"

    UI.message("Building Flutter AAB for release...")
    sh "flutter build appbundle --release"

    UI.success("AAB built successfully at: build/app/outputs/bundle/release/app-release.aab 🎉")
  end

  desc "Deploy AAB to Google Play Internal Testing Track"
  lane :deploy_internal do
    build_aab_release

    UI.message("Uploading to Google Play Internal Testing Track...")
    upload_to_play_store(
      track: "internal",
      aab: "build/app/outputs/bundle/release/app-release.aab",
      skip_waiting_for_build_processing: true
    )

    UI.success("Deployment to Google Play Internal Testing completed! 🚀")
  end
end
Enter fullscreen mode Exit fullscreen mode

You can also add lanes for:

  • Firebase Distribution
  • Beta tracks
  • Automated version bumps

5. Run Fastlane for Android Builds

To build your Android AAB:

cd android
fastlane build_aab_release
Enter fullscreen mode Exit fullscreen mode

To deploy to Google Play Internal Testing:

fastlane android deploy_internal
Enter fullscreen mode Exit fullscreen mode

For Play Store uploads, set up Google Play API credentials as per the official Fastlane guide.

Step-by-Step Setup for iOS CI/CD (Mac Only)

1. Navigate to iOS Directory

cd path/to/your/flutter/project/ios
Enter fullscreen mode Exit fullscreen mode

2. Initialize Fastlane for iOS

fastlane init
Enter fullscreen mode Exit fullscreen mode

Choose “Manual setup” to have full control over your lanes.

3. Example Fastfile for iOS Builds and Deployment

-Simplified code

default_platform(:ios)

platform :ios do
  desc "Build iOS app for release"
  lane :build_release do
    build_ios_app(scheme: "Runner")
  end
  desc "Upload to TestFlight"
  lane :deploy_testflight do
    build_release
    upload_to_testflight
  end
end
Enter fullscreen mode Exit fullscreen mode

-Professional code

default_platform(:ios)

platform :ios do
  desc "Builds the iOS app for release (IPA file)"
  lane :build_ipa_release do |options|
    UI.message("Starting Flutter clean...")
    sh "flutter clean"

    UI.message("Building Flutter iOS release...")
    sh "flutter build ios --release"

    UI.message("Building iOS IPA file...")
    build_ios_app(
      scheme: "Runner",
      configuration: "Release",
      silent: true,
      clean: true,
      output_directory: "build/fastlane/ipa",
      output_name: "Runner.ipa",
      export_method: "app-store" # لو بتبني لـ TestFlight أو App Store
    )

    UI.success("iOS IPA built successfully and located at: build/fastlane/ipa/Runner.ipa 🎉")
  end

  desc "Deploys the built iOS app to TestFlight"
  lane :deploy_to_testflight do |options|
    build_ipa_release
    upload_to_testflight
    UI.success("Successfully deployed to TestFlight! Your app is now being processed by App Store Connect. 🚀")
  end

  desc "Complete CI/CD lane: Builds IPA and deploys to TestFlight"
  lane :ci_cd_ios do
    deploy_to_testflight
  end
end
Enter fullscreen mode Exit fullscreen mode

You can also automate:

  • iOS code signing with Match
  • Beta builds for testers
  • App Store releases
  • Screenshot uploads

4. Running Fastlane for iOS

To build your iOS app:

cd ios
fastlane build_release
Enter fullscreen mode Exit fullscreen mode

To deploy to TestFlight for testers:

fastlane deploy_testflight
Enter fullscreen mode Exit fullscreen mode

Ensure your Apple certificates, provisioning profiles, and Xcode project settings are correctly configured. Fastlane’s “Match” tool can manage code signing across teams.

Bonus: CI/CD Integration with GitHub Actions (Android Example)

Automating builds in CI ensures consistency and saves time. Here’s a GitHub Actions workflow to build Android on every push:

Create .github/workflows/android.yml:

name: Android CI/CD

on:
  push:
    branches: [ main, develop ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Repository
        uses: actions/checkout@v3

      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          flutter-version: "3.x"

      - name: Install Flutter Dependencies
        run: flutter pub get

      - name: Set up Ruby and Install Fastlane
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.1

      - name: Install Fastlane
        run: gem install fastlane -NV

      - name: Build Android AAB with Fastlane
        run: fastlane android build_aab_release
Enter fullscreen mode Exit fullscreen mode

You can extend this workflow to:

  • Upload artifacts to Firebase or Play Store
  • Run automated tests before building
  • Notify your team via Slack or email on success/failure
  • Deploy to Google Play
- name: Deploy to Google Play Internal Testing
  run: fastlane android deploy_internal
Enter fullscreen mode Exit fullscreen mode
- name: Setup Google Play Credentials
  run: echo "${{ secrets.GOOGLE_PLAY_JSON }}" > play-store-key.json

- name: Deploy to Google Play Internal Testing
  run: fastlane android deploy_to_play_store track:internal
Enter fullscreen mode Exit fullscreen mode

Conclusion: Why Fastlane Supercharges Your Flutter Workflow

Fastlane simplifies the most time-consuming parts of mobile development. By automating builds, tests, and deployments:

  • You reduce human errors
  • Speed up delivery cycles
  • Maintain consistent builds across devices and environments
  • Empower your team to focus on writing code, not repetitive tasks

On Mac, you can automate everything — iOS builds, Android builds, uploads, testing, and distribution.

On Windows, you can automate Android builds, deployments, and integrate with CI/CD pipelines.

Pro Tips & Next Steps

  • Use .env files or CI secrets to manage sensitive credentials
  • Automate app versioning with Fastlane plugins
  • Distribute apps to testers via Firebase or TestFlight
  • Implement automated screenshot generation for App Store submissions
  • Integrate Slack or email notifications for CI/CD pipelines
  • Explore tools like Codemagic or Bitrise for advanced pipelines

Once Fastlane is set up, your Flutter project gains professional-grade automation with minimal effort.

ref

https://www.youtube.com/watch?v=vxjyOdNZxkw

https://www.youtube.com/watch?v=1bmwAyJ-P1Y


Originally published on Medium on July 5, 2025.

Top comments (0)