Automating Standalone Expo App Builds and Deployments with Fastlane and Expo CLI

Mark Glagola
Exposition
Published in
4 min readFeb 26, 2018

--

Update: The post below is out of date, and left here for historical reference. Learn more about building iOS projects with EAS Build (a hosted service for building app binaries for your Expo and React Native projects) that automatically uses Fastlane.

Note: This post was revised for expo-cli.

Expo is a fantastic toolset for bootstrapping React Native applications. If you’re an Expo user, you’re likely familiar with Expo’s command-line interface, expo, which will automate much including building your standalone iOS and Android app binaries. However, it won’t help with deploying those standalone binaries to their associated App Store. Thankfully, we can use Fastlane for this.

Below is a tutorial on how to utilize expo and Fastlane to automate your standalone app deployments.

What We’ll Be Doing

We’ll be creating a bash script that will:

  1. Publish your javascript bundle to Expo’s server.
  2. Build your standalone Android app.
  3. Deploy your standalone Android app to the Google Play Store.
  4. Build your standalone iOS app.
  5. Deploy your standalone iOS app to iTunes Connect (Test Flight).

Prerequisites

This tutorial assumes:

  • expo-cli is installed on your machine and you have experience using it.
  • Your standalone Expo app’s credentials for both iOS and Android are stored on Expo’s server. If you’ve never ran expo build:ios or expo build:android commands before, you'll need to run those commands and make sure to choose the Let Expo handle ... option. More info on this process here.
  • Fastlane is installed on your machine and you have some experience using it.
  • You are using a macOS machine. It’s possible you can follow this tutorial on another operating system, but you will experience issues with the fastlane deliver command as it requires a macOS machine with Xcode installed.

Getting Started

Let’s get started! We’ll be creating a bash script that you can run locally on your computer. If you have the chops and are using a build server, you can translate the bash script to fit your needs there as well.

I’ll be breaking apart the script into sections in order to walk through each step. At the end of the post, I’ll include a code snippet of the full bash script.

1. Creating the Deploy Executable

Within your Expo project directory, create a deploy script. You can do this by executing the following commands in your terminal:

2. Script Setup

Let’s set the script’s env to bash and execute set -e so if one of our bash commands fail, the script will exit.

Next, we’ll run npm install. This is more of a precaution, but a useful guarantee that all of your dependencies are installed. Add the following lines to your deploy script:

3. Publish to Expo

Now we’ll be publishing our release to Expo, add the following lines to your deploy script:

Note the --non-interactive flag. This is important to include with all expo-cli commands as it ensuresexpo-cli won't halt the script with any prompts or questions.

Also, notice the --release-channel production flag. Tailor this flag to fit your needs. You can read more about release channels here.

4. Building Your Standalone Android App

Now we’re getting to the good stuff! Let’s build our standalone Android app (.apk binary).

Add the following to your deploy script:

Once we build our android app, we use curl to download the .apk to the current directory.

5. Submitting Your Standalone Android app to the Google Play Store

Next, let’s use fastlane to submit and publish our app to the Google Play Store.

In order to follow this next step, make sure you’ve generated a Google Developers Service Account credentials file and downloaded it to your machine.

Once you’ve downloaded your Google Developers Service Account credentials file, you may add the following code snippet to your deploy script. Make sure to supply the correct path for --json_key <path/to/json_key.json> flag and the correct package name for --package_name flag (i.e. com.pizza.App).

Note the --track production flag, feel free to set this according to your needs. More about fastlane supply command here.

That’s it for automating standalone Expo Android builds and deployments! Let’s move on to iOS.

6. Building Your iOS Standalone App

The iOS build process is nearly identical to Android. I won’t bore you with a reiteration of what each line does. If you need any help or have questions about a specific command, look for the identical command in step #4.

Add the following to your deploy script:

That’s pretty much it. Now we just need to upload the .ipa binary to iTunes Connect.

7. Submitting Your Standalone iOS app to iTunes Connect

Finally, let’s add fastlane deliver command to our deploy script to upload our .ipa binary to iTunes Connect.

Note: This Fastlane command can be run only on a macOS machine with Xcode installed.

You’ll need to set the following environment variables in order to skip Fastlane’s iTunes Connect username-and-password prompt:

  • DELIVER_USERNAME - your iTunes Connect username.
  • DELIVER_PASSWORD - your iTunes Connect password.

You can set these environment variables in your ~/.bash_profile (if you use bash) or in the script using export command.

Wrapping Up

That’s it! All you need to do now is run ./deploy and leave your computer on. Feel free to grab a coffee, go on a run, play pool, work on yourself, read, meditate, or start working again. Some things you won't have to do include: waiting for commands to finish so you can execute more commands, or manually uploading iOS and Android binaries.

If you’ve run into trouble getting your script working, here’s the full script so you can double check your work. Still running into issues? Comment on this post or ping me @mglagola on twitter.

Curious? Follow our guest blogger Mark Glagola on Github and Twitter.

--

--