Fastlane the Right way with Android and Slack….

Umar Saidu Auna
5 min readApr 2, 2019

--

Have you ever gone through the stress of sharing apk files to the rest of your team? then fastlane is for you. Upload APKs to the #apks channel for internal distribution and testing……

GOAL: The goal of this article is to demonstrate how to use Fastlane to send a message and upload APKs to Slack for internal distribution and testing.

What is Fastlane?

Fastlane is an open source platform continuous delivery tool aimed at simplifying Android and iOS deployment written in Ruby, it automates every aspect of your development and release workflow, tedious tasks for Android and iOS developers. It handles all tedious tasks, like generating screenshots, dealing with code signing and releasing your application. Some of the features it offers:

  1. Easily define different jobs for Play store deployment, beta distribution or testing.
  2. Can be integrated with CI frameworks (Jenkins, CircleCI, Travis CI etc.)
  3. Simple to extend and customize functionality and configuration.
  4. All the configuration and tasks are part of your project in Git.
  5. 200+ built-in integrations available (Slack, JIRA, Git, etc.).

So, take a minute to go through their main page if you are not familiar already.

https://fastlane.tools/

So lets begin by setting up fastlane and Ruby.

#STEP 1: Setting up Fastlane and Ruby

Our operating system is Ubuntu 18.04.1 LTS, First we need to install ruby on your system

Setting up ruby..

On your terminal, navigate to your project folder and run the following command to install fastlane:

Open your project directory then run terminal in your project folder and run the following command below:

Provide the package name for your application when asked e.g “com.example.fasttest”

press enter when asked for the path to your json secret file, choose “N” when asked if you plan on uploading the info to Google Play via fastlane (actually not our goal for now maybe some other time 😄)

That’s it fastlane will automatically generate a configuration for you based on the information provided.

fastlane init in terminal
Appfile and Fastfile

The Fastlane related files can be found under the Fastlane folder, on the root of your project:

./FastFile*: where you define your automation tasks called lanes.

Example: Tasks to run tests, assemble a debug build & upload your beta app to Slack, Crashlytics, deploy/upload a new version to Google Play… etc

./AppFile: It defines configuration information that is global to your app.

NOTE: The most interesting file is fastlane/Fastfile, which contains all the information that is needed to distribute your app.

We are going to focus on two main actions: gradle and slack. These actions offer a lot of common tasks that we come across everyday.

Appfile
fastfile

💡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.

We are going to modify our fastfile code for slack APK upload and make it look like this:

Don’t worry the ruby code will be shared on github 😄…..

Link to the Above code

#STEP 2: Slack Integration

Slack is a great collaboration tool that simplifies engineering workflows for faster deployment.

We will achieve our goal of sending a message and uploading an APK to Slack 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.)

goto https://api.slack.com/slack-apps to begin the setup

Open the link above in your browser, then login into your workspace and choose your slack work space then create app in slack.

After a successful app creation you should see Incoming web hook option in Menu. Then activate Incoming web hook.

Switch Activate Incoming Webhooks to “ON” then Add new webhook to workspace.

Select the channel you want to post the message and APK and click on Authorize, it will generate a web hook url that looks like this:

https://hooks.slack.com/services/xyxyxy/yyyyyy/xxxxxxxxxxxxxxxxx

Copy your generated web hook url and paste it in ENV[“SLACK_URL”]

lastly we are going to generate our access token and grant permission to Upload and modify files as user.

Scroll down and you will see Scope then select “Upload and modify files as user” from the drop-down menu then select save changes

To upload APK to slack run this below line on terminal inside the project directory.

#STEP 3: Testing

The below video shows how the apk is been deployed to slack..

Here’s a screenshot of the slack message:

Congratulations!

You have now successfully sent a message and upload an APK to Slack using Fastlane!

Yes we did it……………

Conclusion

Fastlane allowed us to simplify a tedious release process, making it also way faster and less error-prone. Now we can dedicate the time we usually allocate for the release to build awesome features.

Thank you for reading.

Here’s the link to the Github repo

--

--

Umar Saidu Auna

Kotlin Evangelist and Flutter Warrior | Tech Community Organizer, GDG Minna | Volunteer @nrcs_ng