Automated Flutter Application Deployment Using Fastlane- PART 1
Umar Salim
July 18, 2021
3 min

Why Automate

At YourStory we have a very flexible release schedule aligned with the Agile Methodology. We are very quick with implementing and integrating new features and try our best to be as quick with updates as possible while at the same time maintaining a standard of stability with each of our release versions. This presents a challenge of its own, as we always release updates to both our Android and iOS apps together and anyone who has deployed on both platforms at once will know about the time it takes to get the builds out. On average it took me around 1-1.5 hours to get builds to our QA team. It was clear that this was a problem that was begging for automation.


Why Fastlane?

In trying to automate this whole process (Getting a build from Dev to QA), I went through many solutions, one of them was Fastlane.

Fastlane is an open source platform that automates our deployment process. It has various sub modules aimed at simplifying the release process through automation. The Flutter team has a very thorough documentation on Fastlane and although it will set up Fastlane on your system it has some major drawbacks. The biggest of them is that it doesn’t support both iOS and Android build/deployment from a single Fastlane file. That means we have to maintain two different Fastlane setups- one working inside the android directory and the other inside the iOS directory. This also means we can’t build and deploy both using a single Fastlane command which isn’t ideal. This was a dealbreaker for me as I did not want to maintain different release process for different platforms as well as deploy android and iOS builds separately.

This was until I found a fastlane-plugin-flutter by dotdoom. Unlike the default Fastlane build process, this plugin works on the root flutter project directory allowing us to build and deploy android and iOS apps from a single command from a single Fastfile. We also want to send an email once our builds are deployed, for this we’re using a very convenient fastlane-gmail-plugin by RedMadRobot. Please consider giving these projects a star on GitHub as they have made it possible to have seamless deployments available through their plugin.

Setting Up Fastlane

First, install Fastlane on your system using the following command

Once fastlane is installed, we will need to install the Flutter plugin for fastlane. As mentioned, this is a community-developed plugin as there is no official plugin from the Flutter side. That said, we’ve been working with this plugin for some time now and it’s quite stable.

Change directory to the root of our flutter application and run this command

  This would install fastlane in our current project.

Now that fastlane is already installed and connected to our project, we can continue with installing the Flutter, Google Drive and the Gmails fastlane plugins respectively.

In the same directory where we called the flutter plugin installation command, we run this

  Congrats, you have set up your deployment environment.

Now, let’s edit our fastfile, to create our own lanes, that will build both Android and iOS build files, upload the android apk/aab on our google drive, and our IPA on testflight. Once these tasks are done, it will send an email with the link of our google drive file to email addresses. You can copy over the code snippet present below and paste it into your fastfile.

Google Drive Configs

Now, before we can set up our google drive flow. We need to create a service account that will be given the access required to upload our APK to our google drive folder. You can follow the official docs here to create a service account and make sure to give read/write access of google drive to the same.

Once the service account is created, please download the secret JSON file for the account.

Now navigate to the folder on our google drive storage where we want to upload our APKs and give admin access to that particular folder to our service account’s email address. This email address can be found in the service account menu within the google cloud dashboard.

Creating our Default ENV File

We will need to create a default env file that will contain confidential details such as our passwords and other credentials. Please make sure to add this in your gitignore file to not push this to your remote code repository. You can just paste your credentials in the file below and save it in your project’s fastlane directory.

Running our lanes

Now that everything’s set up, we can just call our deploy lane and sit back.

  As you can see in our Fastfile, the deploy lane first executes our build sub lane, once that is successfully done, it’ll go to our upload_drive_testflight lane, and finally send an email through the email_send sub lane.

Our Fastfile is a ruby script, hence we can modify it completely to add custom lanes, and custom build variants to be able to build and maintain different flavors and release trains, main files, and so on. So feel free to experiment with the Fastfile.

© 2021, All Rights Reserved.

Quick Links

Advertise with usContact Us

Social Media