Automate building Flutter apps using GitHub Actions
In this article, we’ll automate building a Flutter app using GitHub Actions. GitHub Actions is GitHub’s CI/CD solution, it allows you to set up workflows that are triggered by events. Workflows can be triggered on PR creation, code being pushed, manual interaction and many other events.
GitHub Actions workflows are created as yaml files in .github/workflows/
directory. The basic structure of the workflow yaml file is:
name: Workflow name
on: [push] # triggering event
jobs:
job_id:
runs-on: some-os # e.g. ubuntu-latest
steps:
- uses: some-action # e.g. checkout
with:
param_1: 'value-1'
# e.g. many workflows use multiple actions
- run: some command # e.g. flutter build
Check out a complete example on GitHub: https://github.com/minibuildsio/flutter_grid_example.
Build the appbundle for Android
To set up a workflow to build an Android appbundle create .github/workflows/build_android.yaml
and copy the following into the file. The workflow has the following steps:
- Check out the repository.
- Install the flutter tools.
- Install Java 11.
- Run flutter commands
pub get
,test
, andbuild
to get dependencies, run the tests, and build the project. - Upload the appbundle.
name: Build Android App
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
- run: flutter pub get
- run: flutter test
- run: flutter build appbundle
- name: Upload Artifact
uses: actions/upload-artifact@v1
with:
name: android
path: build/app/outputs/bundle/release/app-release.aab
After this has run successfully you’ll be able to download the appbundle from the Artifacts section of the build page, for example, at the bottom of this page.