Release Apps Faster with Fastlane

Ketan Vichare
3 min readJul 16, 2021

--

Photo by Ryu Euiseok on Unsplash

We have made our mobile App ready. Now it's time to deploy and distribute it. Of course, that can be done manually. But, it is quite a time-consuming and repetitive process that does not add any value to our product. (or Read as: We devs are too lazy to do this stuff manually!) Fastlane is to the rescue!

Let’s see how can we integrate Fastlane into our mobile repos.

The initial setup -

Fastlane is a set of ruby commands so its pre-requisite is to have ruby installed on your machine. Check the ruby version on your machine with the command

ruby -v

If it is not already installed, You can find installation instructions from here.

For macOS users system ruby is not recommended to avoid conflicts with system params. The easiest way is to use Homebrew and you should be good. With Homebrew, use the below brew command.

brew install fastlane

Now, let’s go to our project directory and run -

fastlane init

With the interactive run, first, you will need to specify the app package. Secondly, It will ask you the path to the JSON secret file which will be required for Google play upload. You can ignore it for now and also say ’n’. We are down with the initial configuration.

You can observe that these steps have generated a Fastlane directory which contains Fastfile and AppFile.
- AppFile will contain info regarding package name and JSON path.
- Fastfile is the one where all magic happens!
In FastFile, we specify different lanes. Each lane has its job to do.
e.g. Run unit tests, create debug builds for QA or create release build and upload to play store.
These lanes will be triggered from workflows added in Github actions. More about Github actions later.

Each lane will have steps that may include shell commands or Gradle commands. In addition to these, we can use built-in actions which will perform the desired job.
e.g.
-
build_android_app(task: “:app:assembleAlpha”) will generate an alpha artifact
- firebase_app_distribution() will be responsible for uploading the build on Firebase App Distribution.
Let's have a look at some Fastfile scripts.

In the above example, we can see 3 lanes.
- lane :test to run unit tests.
- lane :alpha to generate an alpha build. Further, this build will be shared on the Firebase App distribution.
- lane :playStoreRelease to generate a release build. With the help of upload_to_play_store() build will be uploaded to the Google play store.
We can add more lanes as per our requirements.

Note: credential JSON file will be generated when we add a new service account on Google Cloud Console under your project. This can be downloaded only once on Service Account creation and needs to be saved cautiously.

Fastlane can be integrated with many CI/CD pipeline tools Bitrise, CircleCI, and Github Actions to name a few.

The next part is to get this lane triggered on certain events such as running unit tests on Pull Request creation or publishing the build in store on master merge event.
Let’s see how can we integrate Fastlane with Github Actions to have our CI/CD pipeline complete in the next post — Get in action with Github Actions.

Feel free to share, comment and clap if you found this article useful :)

--

--