Introduction
In the previous article, I explained how to automate iOS builds and TestFlight uploads using Fastlane in a React Native project.
Now let’s continue the automation journey by setting up Android deployment automation using Fastlane.
Managing Android releases manually can quickly become repetitive. A typical release process usually involves:
- Updating versionCode
- Cleaning Gradle builds
- Generating APKs manually
- Uploading builds to Firebase
- Sharing APKs with testers
- Adding release notes
As projects grow, this becomes slower and more error-prone.
Fastlane helps automate the entire workflow — from generating APKs to distributing them through Firebase App Distribution.
By the end of this guide, you’ll be able to:
- Automatically increment Android version codes
- Generate Debug or Release APKs
- Upload builds directly to Firebase App Distribution
- Attach release notes automatically
- Reduce repetitive manual release work
What is Fastlane?
Fastlane is an open-source automation tool for Android and iOS deployments.
It helps automate tasks like:
- Building APKs or AABs
- Managing version codes
- Uploading builds
- Running deployment workflows
- Integrating with CI/CD pipelines
Instead of manually performing release steps every time, Fastlane allows you to automate everything using one command.
Prerequisites
Before starting, make sure you have:
Fastlane Installed
Install Fastlane globally:
brew install fastlane
Verify installation:
fastlane –version
Firebase App Distribution Setup
Your React Native app should already be connected to Firebase.
You’ll also need:
- Firebase Project
- Firebase App Distribution enabled
- Firebase App ID
You can find the App ID inside the Firebase Console.
Step 1 — Initialize Fastlane
Inside the android directory, initialize Fastlane:
fastlane init
Fastlane will create a new structure like this:
android/
└── fastlane/
├── Fastfile
├── Appfile
└── Pluginfile
Step 2 — Install Required Plugins
We’ll use:
- Firebase App Distribution plugin
- Version code increment plugin
Install both plugins:
fastlane add_plugin firebase_app_distribution
fastlane add_plugin increment_version_code
Step 3 — Configure the Appfile
Open: android/fastlane/Appfile
Add your package name and Firebase credentials:
json_key_file(“firebase-service-account.json”)
package_name(“com.example.app”)
Step 4 — Configure Your Fastfile
Approach One (Basic)
Open: android/fastlane/Fastfile
Add the following configuration:
default_platform(:android)
platform :android do
# Lane to increment versionCode
lane :increment_version do
# Fetch the latest release from Firebase App Distribution
latest_release = firebase_app_distribution_get_latest_release(
app: “”1:0000000000:xxxx:xxxxxxx”” # Replace with your Firebase App ID
)
# Increment the versionCode by 1 from the latest release
increment_version_code({ version_code: latest_release[:buildVersion].to_i + 1 })
end
desc “Build and upload the APK (Release) to Firebase App Distribution”
lane :upload_to_firebase do
# Increment versionCode before building
increment_version
# Clean Gradle build
gradle(task: “clean”)
# Build the APK
gradle(
task: “assemble”,
build_type: “Release”
)
# Upload the APK to Firebase App Distribution
firebase_app_distribution(
app: “1:0000000000:xxxx:xxxxxxx”, # Replace with your Firebase App ID
testers: “amitkumar@domain.com”,
release_notes: File.read(“../../release_notes.txt”) # Ensure correct path to your changelog file
)
end
desc “Build and upload the APK (Debug) to Firebase App Distribution”
lane :upload_to_firebase_debug do
# Increment versionCode before building
increment_version
# Clean Gradle build
gradle(task: “clean”)
# Build the Debug APK
gradle(
task: “assemble”,
build_type: “Debug”
)
# Optional: Upload the APK to Firebase App Distribution
firebase_app_distribution(
app: “1:0000000000:xxxx:xxxxxxx”, # Replace with your Firebase App ID
testers: “amitkumar@domain.com”,
groups: “your-group-team-id”,
release_notes: File.read(“../../release_notes.txt”) # Ensure correct path to the changelog file
)
end
end
Recommended: Approach Two (Interactive & Scalable)
This version gives a cleaner and interactive deployment experience:
The most efficient and maintainable way is to use a single interactive Fastlane script. This approach streamlines versioning, building, and distributing your app while allowing users to choose options like build type and tester group—making the process both flexible and scalable.
default_platform(:android)
platform :android do
# ———————————————— Helper Methods ————————————————
def select_build_type
UI.select(“Which build type do you want to generate?”, [“Debug”, “Release”])
end
def select_distribution_group
UI.input(“Enter Firebase tester group (or emails separated by commas):”)
end
def confirm_build(build_type, group)
UI.important(“You are about to build a #{build_type} APK and distribute it to: #{group}”)
unless UI.confirm(“Proceed?”)
UI.user_error!(“Cancelled by user.”)
end
end
# ———————————————— Main Lane ————————————————
desc “Build and distribution workflow for YOUR PROJECT NAME”
lane : upload_to_firebase do
# Display beautiful header
UI.header(“🚀 YOUR PROJECT NAME DEPLOYMENT WORKFLOW 🚀”)
puts “”
UI.message(“Welcome to the YOUR PROJECT NAME deployment tool!”)
UI.message(“This will guide you through building and distributing the app.”)
puts “”
# Get user inputs
build_type = select_build_type
group = select_distribution_group
# Confirm before proceeding
confirm_build(build_type, group)
# Build process
UI.header(“⚙️ BUILD PROCESS”)
increment_version
gradle(task: “clean”)
gradle(
task: “assemble”,
build_type: build_type
)
# Distribution
UI.header(“📦 DISTRIBUTION”)
firebase_app_distribution(
app: “1:0000000000:xxxx:xxxxxxx”, # Replace with your actual Firebase App ID
groups: group,
release_notes: File.read(“../../release_notes.txt”)
)
UI.success(“🎉 Successfully built and distributed the #{build_type} APK!”)
end
# ———————————————— Versioning ————————————————
lane :increment_version do
latest_release = firebase_app_distribution_get_latest_release(
app: “1:0000000000:xxxx:xxxxxxx” # Replace with your Firebase App ID
)
increment_version_code(version_code: latest_release[:buildVersion].to_i + 1)
end
end
What This Setup Does
Automatically Increments Version Code
Before every build, Fastlane fetches the latest Firebase release and increases the versionCode.
This avoids manual version tracking.
Generates APKs Automatically
The script:
- Cleans previous Gradle builds
- Generates Debug or Release APKs
- Uses standard Gradle tasks
Uploads Directly to Firebase
After the APK is created, Fastlane automatically uploads it to Firebase App Distribution.
You can distribute builds to:
- Individual testers
- Multiple tester emails
- Firebase tester groups
Distribution Examples
Single Tester
testers: “tester@company.com”
Multiple Testers
testers: “qa@company.com,dev@company.com,tester@company.com”
Firebase Group
groups: “android-team”
Step 5 — Add Release Notes
Create a release notes file in your project root:
release_notes.txt
Example:
New Features
- Added voice search support
- Improved onboarding experience
Fixes
- Fixed Android 14 crash
- Resolved notification delay issue
Step 6 — Run the Build
Release APK
cd android && fastlane upload_release
Debug APK
cd android && fastlane upload_debug
Firebase Authentication Setup
If Firebase upload fails initially, authenticate using Firebase CLI.
Install Firebase tools:
npm install -g firebase-tools
Login to Firebase:
firebase login –reauth
After authentication, Fastlane should upload builds successfully.
Final Thoughts
Fastlane makes Android release management dramatically easier for React Native teams. Instead of manually updating versions, generating APKs, and uploading builds to Firebase, the entire process becomes automated and reliable.
With a proper Fastlane setup, your Android deployment workflow becomes:
- Faster
- Cleaner
- More scalable
- Less error-prone
Once combined with automated iOS deployment, you’ll have a complete mobile CI/CD pipeline ready for production-scale releases.