Automated Android deployment with Fastlane on Windows

Although the Google Play deployment process is not nearly as complicated as the Appstore deployment of iOS apps, we still could save a lot of time automating Android deployments.

In our App development team, we all develop for both iOS and Android but have different setups as some uses a Mac for both iOS and Android development and others have Windows PC for Android development and a Mac mini for iOS development. So we needed an automated Android deployment setup, that would work on both Windows and Mac OS.
The reason this is relevant for our choice is that we like a script, that will ask us all the questions about the data needed for an app deployment and handle all our git rules, so that everybody will be able to deploy without much knowledge about the git rules of the project. So we need at least some part of the script to be run on our local machines.

Fastlane has been the industry standard for iOS deployments for years and have for a few years also supported Android – but only from Mac’s. But it is actually possible to run Fastlane on a Windows machine.

Here is a guide to setup Fastlane on Windows

# Note: Find an automated setup script in the end

Install ruby

Download .exe installer here

Install Fastlane

This could just be done with this command: gem install fastlane –NV

But a better setup will be to use bundler, as it installs Fastlane locally for the app project, so that you can have different versions of Fastlane of different projects.

Setup Fastlane with bundler like this: (this is as also described in the Fastlane setup guide)

gem install bundler
bundle init
bundle add fastlane
bundle install

We experienced that on some machines bundle install, where the error message says something about that it needs ridk to be installed.

Install it with this command: ridk install 1 2 3

Make sure to add Gemfile and Gemfile.lock to source control.

You will need a terminal to run in interactive mode to be able to run Fastlane commands. I use Hyper but you can just use your own favorite terminal that supports this mode. To test if your terminal supports interactive mode just run command fastlane and you will get this error, if it does not support it: “Could not retrieve response as fastlane runs in non-interactive mode”.

Then you are ready to setup Fastlane for your Android project with: bundle exec fastlane init

Fastlane on Windows quirks

You are now up and running, but you will properly still run into a lot of quirks, where it is obvious that it was initially designed for iOS deployment from Mac OS. Here are some of the quirks we have experienced.

Git quirks

Some Fastlane build in git commands works differently on Windows and Mac OS. For instance, git_branch always return empty on Windows. We solved this by adding a dependency for the gem git with require ‘git’ and added this method to get current branch. It will use current branch if possible to get it on Mac OS, but fallback also work on Windows:

We rewrote most of our git commands to use sh("git …") but also the shell command. You should be aware that it works differently for some of the more exotic git command and tricks like when using something like ||.

For instance to either checkout the branch or create a new branch if it does not exist, you will require a command with the || operator. We solved that so it works on both Windows and Mac OS like this:

Crashlytics beta quirks

We are using Crashlytics beta to distribute test versions, but that also required a trick to get working. When running crashlytics from the Fastfile, the first thing it does is ensure that the crashlytics upload jar is downloaded. But this download seems to fail, but it is possible to fix the by manually download it here and extract it to this location: C:\Users\*username*\Library\CrashlyticsAndroid\. To make sure that it always have the latest code here you should download the latest version as a startup of the lane.

Scripts to automate setup

We have made a powershell setup script for all new developers on our app teams. It handles the setup of fastlane and its dependencies. Find it here as a gist.

See also a gist with our Fastfile that we uses on Windows to deploy Android.
(Note that some of the lanes is executed by CI – we use Gitlab to execute the fastlane script just as with iOS)

See the fastlane Android documentation for further details about fastlane setup.

Kategorier: App, Udvikling