Fastlane + CircleCI for Android — Part 2

Chan Bo
Open Knowledge
Published in
4 min readMar 18, 2019

Welcome back again! In this article I’m going to continue implement Fastlane + CircleCI in previous example with Slack Integration. We will use slack for sending android apk to slack for QA or Client.

Send APK to Slack

Slack Provide a lot of API but now we want to use only Incoming Webhooks or File Upload API.

For more about Slack API, you can look at here.

Incoming Webhooks

The simple way to post messages from apps into Slack. Creating an Incoming Webhooks give you a unique URL to which you send a JSON payload with the message text and some options. To set up Incoming Webhooks, you can look at this Instruction.

File Upload API

This API allows you to create or upload existing file. This API require token get from OAuth. For more detail you can look at file.upload.

Since we want to send apk to slack so I will use File Upload API to upload apk to Slack Channel.

You can follow steps below to integrate slack into Fastlane:

  • Click on permission scope.
  • In OAuth Token & Redirect URLs add OAuth redirect URL
  • In Scopes > Select Permission Scopes > Administer the Workspace
  • Go to OAuth Tokens & Redirect URLs again and Install App to Workspace > Authorize
  • You will see your OAuth Access Token at Tokens for you Workspace.

Even we have OAuth Access Token, we still cannot use file.upload because it require files:write:user. We have to request that permission to use file.upload API.

Working with Scopes

When making the initial authorization request, your application can request multiple scopes as a space or comma separated list. (e.g. team:read users:read)

We can use URL below to make request:

https://slack.com/oauth/authorize?client_id=your_client_id&scope=files:write:user

Open your browser and run URL above and click on Authorize. It will redirect to your Redirect URL.

Right click on your Browser > Inspect Element > Network. You will see your code.

Open Postman make a POST request https://slack.com/api/oauth.access with body:

  • client_id : issued when you created your app (required)
  • client_secret : issued when you created your app (required)
  • code : a temporary authorization code (required)

After request was success, you’ll receive JSON response containing access_token . You can use this token for file.upload API. You can test it here.

You can look for more detail about file.upload API here.

Now let’s get back to Fastfile configuration. We will create a new lane for sending apk to slack channel.

Then run $ bundle exec fastlane send_apk_to_slack apk_path:"your/apk/path" . Go to your Slack Channel you will see your APK.

That’s it about how to use slack for sending apk with fastlane.

Beta Deployment

We will create a new lane name beta to publish app to beta track and deploy to crashlytics(Fabric).

You can run lane beta via $ bundle exec fastlane beta apk_path:"your/apk/path"

If you don’t know how to set up crashlytics in fastlane, you can look at Fastlane for Android — Automate Everything (Part 3).

Release Deployment

We will have a new lane name release to release app to production track. This lane doesn’t have much change with Beta Deployment above. We just have to remove parameter track'beta' inside upload_to_play_store .

This is all about Fastfile configuration. For full Fastfile configuration, you can look at here.

That’s it! In this article we’ve already finish Fastfile configuration. So in the next article, I will implement CircleCI for this example. If you have any question, please let me know! 😎 Thanks.😄

--

--