Deploying CI/CD for Android Mobile Application with Flutter, GitHub Actions, Fastlane, and Google Play
To establish a CI/CD pipeline using GitHub Actions for our existing Flutter application, supporting the following (automatically) after our preferred trigger (push on branch, create pull request, etc.):
- Setup Fastlane and all configurations related to Fastlane
- Building Android app bundle
- Incrementing Google Play Version Code
- Signing the produced packages with a given Keystore
- Deploying the packages to Google Play alpha/internal/production tracks
Fastlane can be installed in multiple ways, but in this project, we will set up Fastlane with Bundler.
It is recommended to use Bundler and a Gemfile to define the Fastlane dependency. This clearly defines the Fastlane version and its dependencies and speeds up execution.
# Install Bundler
gem install bundler
Create a ./Gemfile
in the root directory of your project with the following content:
source "https://rubygems.org"
gem "fastlane"
Run the following command:
bundle update
Add both ./Gemfile
and ./Gemfile.lock
to version control.
Every time you run Fastlane, use:
bundle exec fastlane [lane]
Navigate to the /android
directory and run:
fastlane init
Provide the package name of your application and the path for the JSON secret file downloaded from Google Play Console for your service account.
Supply is a Fastlane tool that uploads app metadata, screenshots, and binaries to Google Play.
- Open the Google Play Console
- Click Account Details and note the Google Cloud Project ID
- Enable the Google Play Developer API
- Open Service Accounts on Google Cloud
- Create a new service account with appropriate permissions
Build your code in release mode to build/app/outputs/[apk][appbundle]/release
directory.
Generate the keystore for signing the app bundle:
keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias my-key-alias
Sign the output app bundle using your keystore:
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.jks app-release.aab my-key-alias
- Sign into your Google Play Console
- Navigate to the Testing section (internal, alpha, beta, or production)
- Click Create Release
- Upload your signed app bundle
Modify android/app/build.gradle
to read version details from a version.properties
file located at /android/version.properties
.
Instead of hardcoding keystore secrets in build.gradle
, use a key.properties
file inside the /android
directory with the following format:
storePassword=your-store-password
keyPassword=your-key-password
keyAlias=your-key-alias
storeFile=my-release-key.jks
Modify your /android/fastlane/Fastfile
to include a lane for deployment to your desired track (alpha, beta, or production).
Example lane:
define :deploy
supply(
track: "alpha",
json_key: "fastlane-secret.json",
package_name: "com.yourapp.app"
)
end
Deploy using:
bundle exec fastlane deploy
Create a workflow file in .github/workflows/google-play.yml
.
Example steps:
- Checkout Code
- name: Checkout code uses: actions/checkout@v3
- Set Up Flutter
- name: Setup Flutter uses: subosito/flutter-action@v2
- Deploy to Google Play using Fastlane
- name: Deploy run: bundle exec fastlane deploy
- Ensure you pull the latest changes before pushing a new release.
- For GitHub Organizations, add necessary permissions to the workflow YAML file.