Seamless Flutter App Deployment: Automate Android Releases with GitHub Actions, Fastlane, and Firebase App Distribution 🚀
In this guide, we will walk you through the steps to automate the deployment of a Flutter Android app using GitHub Actions and Fastlane, distributing it via Firebase App Distribution. This setup will streamline your workflow, ensuring that every push to your main branch results in a new build being distributed to your testers automatically.
Prerequisites
- A Flutter app project.
- A Firebase project set up with Firebase App Distribution.
- A GitHub repository for your Flutter app.
- Fastlane installed:
gem install fastlane
(orbrew install fastlane
on macOS). - GitHub Actions enabled for your repository.
If you are new to Fastlane, refer to my previous article on setting up Fastlane with Firebase App Distribution for detailed instructions: Publishing Flutter Builds with Fastlane and Firebase App Distribution 🚀
Set Up GitHub Actions
Create a GitHub Actions workflow file. In your GitHub repository, navigate to .github/workflows
and create a new file named flutter.yml
:
name: Flutter Firebase CI
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
env:
LC_ALL: en_US.UTF-8
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: 'stable'
- name: Install dependencies
run: flutter pub get
- name: Run tests
run: flutter test
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3' # Specify your ruby version here
- name: Install Fastlane
run: gem install fastlane
- name: Install Fastlane Firebase App Distribution plugin
working-directory: android
run: fastlane add_plugin firebase_app_distribution
- name: Configure Google Application Credentials
run: echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}" > $HOME/gcp-key.json
- name: Run Fastlane for Android
working-directory: android
run: fastlane distribute
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
This workflow file does the following:
- Triggers on every push to the
main
branch. - Sets up JDK 11 and Flutter.
- Installs dependencies, run the tests, and builds the APK.
- Sets up Fastlane and deploys the app to Firebase App Distribution.
Generating Google Services Credentials
For the GitHub Actions workflow to deploy your app, it needs access to your Google Services JSON file. Generate a Google Services JSON by:
- Go to https://console.firebase.google.com/
- Select project
- Navigate to Project Settings > Service Accounts
- Click on Manage Service Account Permissions
- It will redirect to the Google Cloud Console
- Click on Create Service Account
- Enter Service Account Name (This can be any name of your choice)
- Click on CREATE AND CONTINUE
- Select role as Firebase App Distribution Admin
- Click on Done
- Navigate to Service Accounts
- Select the Service Account you just created
- Navigate to the Keys Tab
- Click on ADD KEY
- Select Create New Key
- Choose Key Type as JSON and click on create
- The JSON file will be downloaded to your system
- Keep the file safe
Add Google Services JSON to GitHub Secrets
The downloaded JSON file is required for Firebase services. Follow these steps to securely include its contents in your GitHub Actions workflow:
- Open the downloaded JSON file file in a text editor.
- Copy the entire content of the file.
- Go to your GitHub repository.
- Click on
Settings
. - Navigate to
Secrets
>Actions
. - Click on
New repository secret
. - Add
GOOGLE_APPLICATION_CREDENTIALS
as the name and paste the copied content as the value.
Modify FastFile
After setting up Fastlane following the previous article, navigate to android/fastlane
and open Fastfile
. Modify the Fastfile
to include the credentials for deploying to Firebase App Distribution:
Add the following line:
service_credentials_json_data: ENV['GOOGLE_APPLICATION_CREDENTIALS']
So, the modified FastFile looks like:
platform :android do
desc "My awesome app"
lane :distribute do
build_android_app(
task: "assemble",
build_type: "Release")
# build_android_app is a built-in fastlane action.
release = firebase_app_distribution(
service_credentials_json_data: ENV['GOOGLE_APPLICATION_CREDENTIALS'],
app: "1:123456789:android:abcd1234",
testers: "tester1@company.com, tester2@company.com",
release_notes: "Lots of amazing new features to test out!",
android_artifact_type: "APK",
android_artifact_path: "../build/app/outputs/apk/uat/release/app-release.apk",
)
end
end
Now with every push on main branch, it will run the pipeline with
Conclusion
With these steps, you have set up a continuous deployment pipeline for your Flutter Android app using GitHub Actions and Fastlane, distributing it via Firebase App Distribution. This automation will save you time and effort, allowing you to focus more on development and less on manual deployments.
By integrating these powerful tools, you can ensure that your testers always have access to the latest version of your app, keeping your feedback loop tight and your development process efficient.
For more detailed instructions on setting up Fastlane, refer to my previous article: Publishing Flutter Builds with Fastlane and Firebase App Distribution 🚀
Thanks for reading it! If there’s any mistake, please let me know in the comments so that I can improve. Clap 👏 if this blog helps you!