Automating the Android Build and Release Process using Fastlane -Part I
Fastlane is a great tool that developers can use to automate their release process & significantly reduce their release cycle times. The 4 major features offered by Fastlane are:
- AUTOMATE SCREENSHOTS: Automatically generate localized screenshots for the app store.
- BETA DEPLOYMENT: Easily distribute beta builds to testers.
- APP STORE DEPLOYMENT: Publish a new release to the app store in seconds.
- CODE SIGNING: Reliably and consistently code sign your app–no more headaches.
Since Fastlane allows plugins, there is no restriction on the capabilities. 🚀
NOTE: For these demonstrations, we will be using the CLI tool on a local device, but these tasks can be added to & triggered by your CI tool.
GOAL: The goal of this article is to demonstrate how to use Fastlane to send a message to Slack for internal QA
Below are steps to achieving a successful Fastlane Android Setup: 👇👇
Installing Fastlane
On your CLI (Command Line Interface), navigate to your project folder and run the following command to install Fastlane:
sudo gem install fastlane -NV
Verify that the installation was successful by typing this command in the CLI:
fastlane -version
Setting up Fastlane
Navigate your terminal to your project’s directory:
- Run
fastlane init
( Initializes Fastlane in our project) - Provide the package name for your application when asked (e.g.
com.thedancercodes.fastlanedroid
) - Press enter when asked for the path to your json secret file
- Answer ’n’ when asked if you plan on uploading info to Google Play via Fastlane (we can set this up later)
That’s it! Fastlane will automatically generate a configuration for you based on the information provided.

This process generates our App file and Fastfile. Below is a screenshot of the Fastlane directory in your project containing these files.

Appfile: Defines configuration information that is global to your app.
It designates where your package name and json secret key (the file path to your Google Play console) are.
NOTE: This is what we use to upload an APK to the Google Play console in a future post.
Fastfile: Defines different lanes that drive the behavior of fastlane to do different tasks.
Example: Tasks to run tests, assemble a debug build & upload your beta app to Crashlytics, deploy/upload a new version to Google Play… etc
NOTE: The most interesting file is fastlane/Fastfile
, which contains all the information that is needed to distribute your app.
The Fastfile defines what steps run & in what order Fastlane runs them.
A group of steps is called a lane.
Below are code snippets show the contents of the Fastfile & Appfile:


💡TOP TIP: 💡 It is best practice to keep these files in source control to share with the rest of your team. More on this here.
GOAL: Use Fastlane to send a message to Slack
Slack is a great collaboration tool that simplifies engineering workflows for faster deploys.
We will achieve our goal of sending a message to Slack by using a Webhook.
A Webhook is essentially the slack URL used to be able to post things to slack channels or to specific users when an action happens (e.g. A successful build, a successful APK upload to Google Play using Fastlane… etc.)
NOTE: Webhooks allow us to send data to Slack in real-time.
Prepare for slack integration using Fastlane:
1. Set up slack environment variable.
The first step is to configure the incoming Webhook URL. This is acquired after installing incoming webhook app in your workspace.
Select the channel or direct message you want to post the message to and generate the URL.
Add the URL into thelocal.properties
file that will be referenced in thebefore_all
block of the Fastfile
## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file should *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=/Users/thedancercodes/Library/Android/sdk
# SLACK WEBHOOK URL
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/XXXXXX/XXXXXXXX/XXXXyyyyzzzzAAABBBB
NOTE: The local.properties
file is not part of the files that are added to version control
before_all do# Reads the local.properties file and returns the the slack webhook url.
f = File.open("../local.properties", "r")
ENV["SLACK_URL"] = f.each_line.to_a.last.split('=').last
f.close
end
NOTE: The code in the
before_all
block returns a string with the last line value inlocal.properties
, splits it with an equals sign.split('=')
to separate the key and the value. Finally picking.last
returns the last value after splitting which is the webhook URL.
2. Add an AssembleDebug lane
We will add a lane that builds a debug APK in the Fastfile
after the before_all
block.
desc "Build a debug APK"
lane :debug do
gradle(task: "clean assembleDebug")
end
3. Add the block that sends the Slack message
To the Fastfile
after the debug lane add this block that implements the slack action of sending a message to the specified channel/ direct message
# Runs after all tasks
# This block is called only when the executed lane was successful after_all do |lane|
# Slack action
slack(
message: "Slack Message Delivered Successfully"
)
end
4. Add a check for when the build fails:
We need to add a check for when an error occurs and causes the build to fail.
We create an error
block and pass in lane and exception. We then add a slack action to post a message & set success to false.
error do |lane, exception|
slack(
message: exception.message,
success: false)
end
Below is the complete code for your Fastfile
:
📣GOTCHA: 📣 Always remember to end your blocks.
5. Let's test it out: 🚀🚀
Got back to the terminal and run the command below:
fastlane android debug
This triggers theassembleDebug
task & send a message to slack after the build is successful. See video below.
Here’s a screenshot of the slack message:

Congratulations!
You have now successfully sent a message to slack using Fastlane!

Next steps:
I plan on making a couple of follow up blog posts to this and incorporate topics like:
- Upload an APK to a QA slack channel for your team to review the app internally
- Distribute beta builds to testers using Beta by Fabric.
- Publish a new release to the Google Play Store
- Incorporate Fastlane into your CI pipeline.
You now have the foundational skills necessary to use FastLane in your Android projects.
Thank you for reading.
Here’s the link to the Github repo for example
Major S/O to Chris for helping me with the Ruby scripting in the Fastfile. Thanks for coming through with your Ruby chops. 💪
Also S/O to Isaac Owomugisha, Eston Karumbi and Nabende Simiyu for helping edit this article. ✊