- Flutter Times
- Posts
- Streamline Your Flutter Development with Fastlane CI/CD!
Streamline Your Flutter Development with Fastlane CI/CD!
We’re excited to introduce a step-by-step guide on setting up Fastlane CI/CD deployment for Flutter Flash Template! This setup will automate building, testing, and deploying your Flutter app, creating a streamlined and efficient workflow. Here’s how to set it up:
Step 1: Add Fastlane to Your Flutter Project
Navigate to your project root and run the following commands to install Fastlane for both iOS and Android:
cd android fastlane init cd ../ios fastlane init
Define the lanes in the Fastfile for both Android and iOS. Here’s a sample setup to deploy to Firebase App Distribution.
Define the lanes in the Fastfile for both Android and iOS. Here’s a sample setup to deploy to Firebase App Distribution.
android/fastlane/Fastfile
:default_platform(:android) platform :android do desc "Deploy Android app to Firebase" lane :deploy do gradle(task: "clean assembleRelease") firebase_app_distribution( app: "YOUR_ANDROID_APP_ID", groups: "testers", release_notes: "Automated deployment" ) end end
default_platform(:ios) platform :ios do desc "Deploy iOS app to Firebase" lane :deploy do build_app(scheme: "Runner") firebase_app_distribution( app: "YOUR_IOS_APP_ID", groups: "testers", release_notes: "Automated deployment" ) end end
Replace
YOUR_ANDROID_APP_ID
andYOUR_IOS_APP_ID
with your Firebase App IDs, which you can find in the Firebase Console under Project Settings.
Step 2: Set Up GitHub Actions Workflow
Create a GitHub Actions workflow file in your project by navigating to
.github/workflows
and creatingflutter_ci.yml
:mkdir -p .github/workflows touch .github/workflows/flutter_ci.yml
Define the workflow by adding the following configuration to
flutter_ci.yml
:name: Flutter CI/CD on: push: branches: - main pull_request: branches: - main jobs: build: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v3 - name: Set up Java uses: actions/setup-java@v3 with: distribution: 'zulu' java-version: '11' - name: Set up Flutter uses: subosito/flutter-action@v2 with: flutter-version: 'stable' - name: Install dependencies run: flutter pub get - name: Run tests run: flutter test - name: Build APK (Android) run: flutter build apk --release - name: Build IPA (iOS) [Optional] if: runner.os == 'macOS' run: flutter build ios --release --no-codesign - name: Deploy Android to Firebase using Fastlane env: FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} run: | cd android fastlane deploy - name: Deploy iOS to Firebase using Fastlane [Optional] if: runner.os == 'macOS' env: FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} run: | cd ios fastlane deploy
Step 3: Set Up Secrets for Firebase Deployment
Add
FIREBASE_TOKEN
to your GitHub repository secrets to allow GitHub Actions to authenticate with Firebase:In your Firebase CLI, run:
firebase login:ci
Copy the generated token and go to GitHub Repository Settings > Secrets > Actions, and add it as
FIREBASE_TOKEN
.
Step 4: Commit and Push Your Workflow File
After setting everything up, commit your changes and push to GitHub:
git add .
git commit -m "Add Fastlane CI/CD workflow"
git push origin main
Once you push to the main
branch, GitHub Actions will automatically trigger the workflow, running tests, building the APK/IPA, and deploying the release to Firebase.
Final Workflow Structure Recap
Your Fastlane CI/CD setup with Flutter Flash Template is now complete! Here’s what we’ve achieved:
Automated Testing: Ensures code stability before deployment.
Automated Build & Deployment: Saves time by building and distributing your app instantly with Firebase.
Streamlined CI/CD Workflow: With Fastlane and GitHub Actions, your Flutter project is always deployment-ready!
And a little self-promotion at the end.
For daily posts around being a freelancer and Flutter in general you can follow me on LinkedIn: Parmendra Singh's LinkedIn
I’m also starting to post on Twitter/X and would love a like or even follow there.
And here is a link to my Twitter: Parmendra Tomer on Twitter
Check it out if you want to release your next Flutter app super quick. Flutter Flash Template: Flutter Flash Template
And finally. Thanks for reading.
I really appreciate it.