How to use Github Actions to build Flutter Android 2022 (Part 1 — Fundamentals)

Fooshen C
3 min readSep 18, 2022

--

credit : differencebetween.net

I believe CICD is something common for everyone nowadays. Everyone want process to be automated and time saving but creating the process is always a pain in ass.

Github Actions draws my attention when setting up deployment environment is troublesome and I should work out with a workflow that everyone can use and deploy to PlayStore / Huawei App Gallery without hassle.

Talking about Github actions,

In layman explanation its a CICD (continuous integration & continuous delivery) platform that let user to create workflow to automate task.

User may create their custom workflow to automate deployment, unit testing, code merging etc. I am new to it as well, just to write an article on some fundamentals and knowledge gained from few days studying it.

Get started with Github Actions,

select actions tab in your repository
default sample workflow yml

Syntax :-

On
Contains events that will automatically trigger workflow to run.
workflow_dispatch
Allow user to manually trigger workflow from Github actions tab.

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:

Jobs
Contains multiple jobs that runs in parallel (concurrent)
runs-on
Specify runner environment

environment sample from docs.github.com

steps
Contains multiple actions
needs
Specify dependency on job

jobs:
job_number_one:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: name_of_step_1
run: echo Hello, world!
- name: name_of_step_2
run: |
echo Add other actions to build,
echo test, and deploy your project.
job_number_two:
runs-on: ubuntu-latest
needs: job_number_one
steps:
- uses: actions/checkout@v3
- name: name_of_job2_step_1
run: echo Hello, world!
- name: name_of_job2_step_2
run: |
echo Add other actions to build,
echo test, and deploy your project.

Let’s hop into the flutter part for Github actions, first we need to set up flutter environment, then we can try to build flutter app bundle with it.

lets set up a job call flutter-actions-android.

Add a name to describe what this job do and define the environment it runs. In this case with be on ubuntu-latest.

actions/checkout@v3 is needed , it checkout your repository under Github, so that Github actions can access it.

actions/setup-java@v2 is needed to as java is needed to compile android project.

subosito/flutter-actions@v2 is one of the popular actions to setup flutter environment for Github actions. You may define your target flutter version and channel, then run flutter command with it.

name: CIon:
workflow_dispatch:
jobs:
flutter-actions-android:
name: flutter related actions for android
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.3.1'
channel: 'stable'
- run: flutter --version
- run: flutter pub get
- run: flutter build appbundle

After creating your first yml file, time to try it out for the first time. Trigger your workflow manually at the run workflow in Actions tab right corner.

user may select to trigger workflow for selected branch
done

Well done ! From the log you can see you successfully built an app bundle in the path ‘build/app/outputs/bundle/release/app-release.aab.

Note this down, we going to use it for part 2 ( PlayStore & Huawei Gallery Deployment). Stay tuned !

Thanks for reading, leave some claps for yourself and me if you gain something from this article. 👏 👏

--

--