Automate Flutter app distribution with GitHub and firebase
My experience with delivering application to clients has been subpar till now. using whatsapp to share the apk or using test-flight to upload the ipa which creates unnecessary junk files.
The alternate solution was to upload the application to diawi and send the link to download the application also worked for some time.
But, we know that developers like one thing the most, Automating anything and everything .
Let's get started!!
First start by creating a flutter project and uploading it to Github and configuring firebase.
I will assume you have done that by now.
Setting up github action
Step 1: Once Github is linked to the project. you may find a .github folder in your repository, if it's not present create one.
Step 2: Next you will create a folder named workflows inside the .github folder.
Step 3: Create a main.yml file inside the workflows folder
now your repository would look like this,
[Ignore the ISSUE_TEMPLATE and pull_request_template.md files]
now let's get into automating our app distribution flow.
Step 1: The first step is to define when the action will start. I will configure it such that every-time some code is pushed or merged to develop branch, the action will start.
so, the first line would look like this,
Step 2: Now we need to define the os that will be used to run the action and set up environment for flutter.
Here we are using ubuntu as opposed to mac since later while using firebase app distribution i encountered an error that the firebase action can only run in ubuntu system.
We have to use predefined actions such as checkout@v1, setup-java@v1, flutter-action@v1 to setup java and flutter.
Step 3: Now we can run the flutter commands that will build the application.
Step 4 (Optional): you can upload it to github release too.
The secret.TOKEN and other secret keys can be set up in the github secret properties.
to set that you need to go to: project > settings >secrets
[IMPORTANT] to create a token you need to go to:
Settings > developer settings > personal access token > generate new token and tick all the permissions.
Firebase app distribution
Before adding firebase action you need to setup FIREBASE_APP_ID and FIREBASE_TOKEN in the secrets.
The FIREBASE_APP_ID can be found in the general settings in firebase after you have setup an application.
for FIREBASE_TOKEN you need to execute
firebase login:ci
in the terminal and login with firebase account to get the token.
Step 5: Adding firebase action
Hurray, You have done it.
Lets look at the final code,
If you have reached here,
Thank you for your time. Follow for more flutter related content and tricks.