Flutter – Continuous delivery Android for Flutter App

Tram Ho

Hi guys, to save time building the app and then having to deploy it manually, today I will write an article about Continuous delivery (from local machine) android for deploying Flutter app. Since this is my first post, please forgive me for any mistakes and suggestions to improve the quality of future articles.

Ways to set up Continuous delivery for Flutter app

We can easily find solutions to help deploy Flutter easily on Flutter’s Docs, basically there are 2 main solutions:

  • Use 3rd party services like: Codemagic, Bitrise, Appcircle. (I have used it via Codemagic, quite convenient).
  • Manual configuration using fastlane (in this article I will focus on this solution).

Prerequisites

  • A Google Play Console Developer account is required.
  • The environment required for Flutter App development has been installed.
  • Install the development environment and build the .aab file (android app bundle).

Install and configure fastlane.

After running the command “fastlane init” the terminal will ask for some information:

  • Provide the app’s package name (e.g. my.package.name ).
  • Provide json secret file: press “n” (this step I will set up later).
  • Press ‘n’ when asked “do you intend to upload information to Google Play via fastlane?” (I will set it up later).

After completing the “procedure” fastlane init fastlane will initialize 2 files Appfile (configuring information for the app) and Fastfile (configuring deploy commands) in the android/fastlane directory.

Configure on Google Play Console and Google Cloud Platform to get the “Json secret file” mentioned earlier.

The steps will be as follows:

  1. Open Google Play Console
  2. On the left sidebar, click on Account Details, notice Developer Account ID.
  3. Click Setup API access
  4. Go to Google Cloud Platform
  • Click the Create new service account button. to switch to Google Cloud Platform.
  • Click the CREATE SERVICE ACCOUNT button at the top of the Google Cloud Platform Console page.
  • Verify using the correct Developer Account ID in IAM & Admin → Service Account.
  • Provide Service account name and click Create.
  • Click Select a role, select Service Account User and press continue → Click DONE .
  • Click Actions on the 3-dot icon of the newly created service account → Select Manage keys.
  • Click ADD KEYCreate New Key
  • Select JSON type → click CREATE .
  • Download the file and store it where needed on your computer.
  1. Return to Google Play Store and click the DONE button to close the popup
  2. Click the Grant Access button → Refresh service accounts to update the changes from step 4.
  3. Authorize this account. Suggest Admin (all permissions).
  4. Click Invite user to finish.

Run the first fastlane commands.

After we have configured the necessary things, we will write the service commands for deploy.

  1. First check if you have successfully connected to the Google Play Store, run the command:

  1. When everything is ok, open the file android/fastlane/Appfile to add the json secret file path.

  1. Run the following command to start the configuration.

Note: The Google Play Store requires a first build (version code: 1) uploaded to the Google Play Store before it can deploy future builds.

Android app build configuration

To avoid lengthy posts, you can follow Flutter’s instructions to build your first android app: https://docs.flutter.dev/deployment/android .

Change some config to avoid running fastlane deploy command error.

  1. Add lintOptions: android/app/build.gradle .

  1. In the file android/gradle.properties add the following command line:

  1. In the file android/gradle/wrapper install the project running on gradle 7.5 instead of 6.7 as it is now.

  1. Run the following command to update gradle 7.5

Write the necessary commands for the Deploy

After completing the above steps. Open the file android/fastlane/Appfile.

Configure the build & deploy

Complete the required commands. Let’s start deploying!

Enjoy the results.

After completing the above steps, we have completed Continuous delivery (local machine) for android app. The following builds just need to upgrade the version code and run the following command to upload the file to the Internal Tester (same for beta, production, …)

References

https://docs.flutter.dev/deployment/cd

https://docs.fastlane.tools/getting-started/android/setup/

Share the news now

Source : Viblo