Fastlane - Google Play
Build Flutter apps and automatically upload to Google Play with Fastlane (free)
When a Flutter app starts having many releases, manually building AAB and uploading to Google Play Console is very easy to get wrong. I use Fastlane to automate the full Android release flow.
My goals are:
Reduce manual steps when shipping a new version.
Standardize the process for the whole team.
Clearly separate lanes:
internal,alpha,production.
Prepare the Fastlane environment
Step 1: Install Bundler
gem install bundlerStep 2: Create Gemfile
Create a Gemfile at project root:
source "https://rubygems.org"
gem "fastlane"Step 3: Install local dependencies
bundle config set --local path 'vendor/bundle'
bundle installI prefer this way to lock Fastlane version per project.
Create a service account for Google Play API
Step 1: Create a service account in Google Cloud
Go to: Google Cloud Service Accounts
Do the following:
Select or create a new project.
Create a service account named
fastlane-deploy.Assign role
Editor(for production, consider least-privilege roles).Go to
Keys->Add key-> selectJSONto download the key.Copy the service account email (format
xxx@xxx.iam.gserviceaccount.com).
Step 2: Grant permissions in Google Play Console
Go to: Google Play Console
Open Google Play Console -> Users and permissions -> Invite new user:
Paste the service account email.
Grant the proper release permissions.
No email confirmation is required.
Put the JSON key into the project
Put the JSON file in project, for example:
If you want better security, add this to .gitignore:
Initialize Fastlane for Android
Go to android folder and run:
When prompted, fill in:
Package name:
com.example.appJSON path: for example
./android/fastlane/play-service-account.jsonDownload existing metadata and setup metadata management?->y
After this step, Fastlane will create Fastfile and Appfile.
Configure Fastfile
Edit android/fastlane/Fastfile like this:
Run release lanes in android folder
Quick explanation:
internal: upload to internal track (not public).alpha: upload to closed testing.production: upload to public store.
Fix common issue: Fastlane cannot build AAB because Java is not aligned
Sync JDK for Flutter and Fastlane
Issue I faced:
flutter build appbundleworks.But
fastlanebuild fails because Java versions are different.
Fix (example using Java 17 on macOS Apple Silicon):
Add to ~/.zshrc:
Reload shell and check:
Expected result: openjdk version "17.x.x".
Run Fastlane again:
If running from project root, you can use:
Additional notes
For iOS, I use
devices.txtto manage test devices and auto-add devices in Fastlane flow.This article focuses on Android/Google Play, I will publish a separate iOS article next time.
Conclusion
Fastlane helps me turn a release process with many manual steps into a few fixed commands. After setup, for each new release I only need to bump version and run the corresponding lane.
It becomes much faster if you combine it with Make. If you do not know it yet, check this article.
MakeLast updated