Flutter CI/CD Pipeline Setup: Complete Guide for Automated Build & Deployment

Learn how to set up CI/CD for Flutter apps using GitHub Actions. Automate builds, run tests, generate APK/AAB, and deploy your app efficiently.

Introduction

In modern app development, manually building and releasing apps is inefficient and error-prone.

CI/CD (Continuous Integration and Continuous Deployment) automates your development workflow.

With CI/CD, every code push can:

  • Run tests automatically
  • Build APK/AAB
  • Detect errors early
  • Deploy apps faster

What is CI/CD?

  • CI (Continuous Integration) → Code is tested automatically
  • CD (Continuous Deployment) → App is built & deployed automatically

CI/CD Workflow for Flutter

Developer Push Code
        ↓
GitHub Actions Triggered
        ↓
Install Flutter SDK
        ↓
Run flutter pub get
        ↓
Run Tests
        ↓
Build APK / AAB
        ↓
Deploy or Upload Artifact

Why Use CI/CD for Flutter?

  • Automated builds
  • Faster development cycle
  • Consistent release process
  • Early bug detection

Step 1: Create GitHub Repository

Push your Flutter project to GitHub.

Step 2: Create Workflow File

Create file:

.github/workflows/flutter_ci.yml

Step 3: Basic CI Setup

name: Flutter CI

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

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

      - name: Setup Flutter
        uses: subosito/flutter-action@v2
        with:
          flutter-version: '3.22.0'

      - name: Install Dependencies
        run: flutter pub get

      - name: Run Tests
        run: flutter test

      - name: Build APK
        run: flutter build apk --release

Step 4: Upload Build Artifact

- name: Upload APK
  uses: actions/upload-artifact@v3
  with:
    name: app-release
    path: build/app/outputs/flutter-apk/app-release.apk

Step 5: Build App Bundle (Play Store)

- name: Build AAB
  run: flutter build appbundle --release

Handling Secrets (Keystore)

Store sensitive data in GitHub Secrets:

  • KEYSTORE_BASE64
  • KEY_PASSWORD
  • KEY_ALIAS

Decode in pipeline:

echo "$KEYSTORE_BASE64" | base64 --decode > android/app/keystore.jks

Run Workflow

Every push to main branch will trigger CI pipeline automatically.

CI/CD for iOS (Mac Required)

runs-on: macos-latest

Then build:

flutter build ios --release

Automated Deployment Options

  • Firebase App Distribution
  • Google Play Console API
  • TestFlight (iOS)

Example: Firebase App Distribution

firebase appdistribution:distribute app.apk \
  --app YOUR_APP_ID \
  --groups testers

Best Practices

  • Use separate dev and production branches
  • Run tests before build
  • Store secrets securely
  • Automate versioning

Common Mistakes

  • Hardcoding secrets in code
  • Skipping test step
  • Not using artifacts

Advanced CI/CD Ideas

  • Auto version increment
  • Code analysis (flutter analyze)
  • Multiple environment builds
  • Slack/Email notifications

Production Pipeline Example

Push Code
   ↓
Run Tests
   ↓
Build AAB
   ↓
Upload to Play Store
   ↓
Notify Team

Conclusion

CI/CD is essential for professional Flutter development.

By automating builds and deployments, you can save time, reduce errors, and ship apps faster.

With GitHub Actions, setting up CI/CD for Flutter is simple and powerful.

Share

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0