This guide outlines the process of setting up a CI/CD pipeline for a Flutter mobile application using Fastlane, GitHub Actions, and Firebase App Distribution. The pipeline automates building, testing, and distributing the app, streamlining development and ensuring rapid, consistent deployments.
- Setting Up Flavors in Flutter
- Firebase Configuration
- Installing Fastlane
- Integrating Firebase with Fastlane
- Setting Up GitHub Actions
- Running the Pipeline
- Conclusion
- References
{
"version": "0.2.0",
"configurations": [
{
"name": "APP_NAME Development",
"request": "launch",
"type": "dart",
"program": "lib/main_development.dart",
"args": ["--flavor", "Development", "--target", "lib/main_development.dart"]
},
{
"name": "APP_NAME Production",
"request": "launch",
"type": "dart",
"program": "lib/main_production.dart",
"args": ["--flavor", "Production", "--target", "lib/main_production.dart"]
}
]
}
flavorDimensions "default"
productFlavors {
production {
dimension "default"
resValue "string", "app_name", "APP_NAME Production"
}
development {
dimension "default"
applicationIdSuffix ".dev"
resValue "string", "app_name", "APP_NAME Development"
}
}
<application
android:label="@string/app_name"
...>
...
</application>
Build Command
flutter run --release -t lib/main_production.dart --flavor production
-
Create a new Firebase project on the Firebase console.
-
Login to Firebase:
-
firebase login
-
-
Install and configure FlutterFire CLI:
-
dart pub global activate flutterfire_cli flutterfire configure flutter pub add firebase_core flutterfire configure
-
-
Install Ruby:
-
Install Fastlane (in cmd):
-
gem install fastlane
-
-
Initialize Fastlane (in project root):
-
cd android fastlane init
-
-
Add the Firebase App Distribution plugin:
-
fastlane add_plugin firebase_app_distribution
-
-
Login to Firebase CLI:
-
Save the token for later use.
firebase login:ci
-
-
The
..\android\fastlane\Fastfile
file will be automatically created, update it with the following:-
default_platform(:android) platform :android do desc "Lane for Android Firebase App Distribution" lane :firebase_distribution do sh "flutter clean" sh "flutter build apk --release --flavor production --target lib/main_production.dart --no-tree-shake-icons" firebase_app_distribution( app: "1:383408612193:android:da0f9d86c0a8051e4c5b20", firebase_cli_token: ENV["FIREBASE_CLI_TOKEN"], android_artifact_type: "APK", android_artifact_path: "../build/app/outputs/flutter-apk/app-production-release.apk", testers: "[email protected]", release_notes: "YOUR_RELEASE_NOTES_HERE" ) end end
-
-
Secure your data in GitHub Secrets:
-
Firebase options (4 secrets)
- FIREBASE_OPTIONS_ANDROID_API_KEY
- FIREBASE_OPTIONS_ANDROID_APP_ID
- FIREBASE_OPTIONS_IOS_API_KEY
- FIREBASE_OPTIONS_IOS_APP_ID
-
Fastfile (2 secrets)
- FIREBASE_CLI_TOKEN
- APP_ID
-
-
Create a GitHub Actions workflow file
..\.github\workflows\android_fastlane_firebase_app_distribution_workflow.yml
:-
name: Android Fastlane with Firebase App Distribution Workflow on: push: branches: - mobile-app-stable # The branch that you would like to run the workflow when you push into it. jobs: distribute_to_firebase: runs-on: ubuntu-latest steps: - name: Checkout my repo code uses: actions/checkout@v2 - name: Set up JDK 11 uses: actions/setup-java@v2 with: java-version: "11" distribution: "temurin" - name: Install Flutter uses: subosito/flutter-action@v2 with: channel: stable # If there was an error, then run this: "cd android" then "bundle lock --add-platform x86_64-linux" - name: Setup Ruby uses: ruby/setup-ruby@v1 with: ruby-version: "3.3.4" bundler-cache: true working-directory: android - name: Build and Distribute App env: APP_ID: ${{ secrets.APP_ID }} FIREBASE_CLI_TOKEN: ${{ secrets.FIREBASE_CLI_TOKEN }} FIREBASE_OPTIONS_ANDROID_API_KEY: ${{ secrets.FIREBASE_OPTIONS_ANDROID_API_KEY }} FIREBASE_OPTIONS_ANDROID_APP_ID: ${{ secrets.FIREBASE_OPTIONS_ANDROID_APP_ID }} FIREBASE_OPTIONS_IOS_API_KEY: ${{ secrets.FIREBASE_OPTIONS_IOS_API_KEY }} FIREBASE_OPTIONS_IOS_APP_ID: ${{ secrets.FIREBASE_OPTIONS_IOS_APP_ID }} run: | bundle exec fastlane android firebase_distribution working-directory: android
-
- Push your code to GitHub.
- GitHub Actions will trigger the workflow on the
mobile-app-stable
branch. - The workflow will build the APK and deploy it to Firebase App Distribution.
- Testers will receive the APK via Firebase App Distribution.
Now, no more sending APKs via WhatsApp! 😂
Setting up a CI/CD pipeline with Fastlane, GitHub Actions, and Firebase App Distribution can greatly streamline your mobile app development process. It ensures that your code is always in a deployable state, automates repetitive tasks, and enables rapid, consistent releases.
Happy Coding! 🚀