Automating Unity Builds — Part 2 : Exporting iOS Binary

Photo by Hello Lightbulb on Unsplash

This is the second part of a blog series of how we construct our system to automate building Unity projects. You can refer of the overview of this process here.

In the previous post, we have managed to configure Unity build process via command-line. While building binaries for Android is more straightforward, binary generation for iOS builds requires more steps.

There are a lot of “pain points” when exporting an iOS project. First, we need to deal with the code signing, which is tedious and error-prone. Then, we need to manually configure the XCode project, making sure all the required services and provisioning profiles are correctly set. We then Archive the project, which is time-consuming, and only after that we can upload to beta distribution services such as Testflight.

In order to automate those process, we are going to use an open source automation tools called Fastlane. Fastlane is a suite of tools that simplifies a number of development process, such as :

  • Manages consistent code signing across different machines
  • Building and exporting binaries
  • Distributing to Beta distribution and App Store platform

Fastlane can be installed by using RubyGems or brew on most modern MacOS machines.

Automating Codesigning Process

Managing Apple credentials for different machines is tedious and time-consuming. There are multiple apps and target distribution that needs to be handled. Each of them also have different expiry dates, and also not to mention we also need to handle list of included devices. Manual approach will be prone to errors, resulting in unnecessary time wasted.

Thankfully, we can use Fastlane’s Match feature for this. As quoted from the docs:

A new approach to iOS code signing: Share one code signing identity across your development team to simplify your codesigning setup and prevent code signing issues.

Match will securely store and manage all of your credentials and provisioning profiles in git repository of your choice. Any machine that requires the credentials can access them in one centralized location. An example match command looks like this:

The command will get development credentials for an app with bundle_id . It will fetch the credentials using the apple_id, and store it in the repo defined by repo_url.

After we handle codesigning, it is time to automate the IPA export process.

Automating Configure and Archive IPA

Archiving IPA for Unity projects takes a lot of time, especially for big projects. It also uses up your Mac’s resources pretty heavily, slowing down your Mac, making your work more difficult. Furthermore, it requires some manual steps, from setting the provisioning profiles, archiving, and exporting it.

Fastlane has a feature for this as well, called Gym. Another quote from the docs:

gym builds and packages iOS apps for you. It takes care of all the heavy lifting and makes it super easy to generate a signed ipa or app file 💪

The following is an example command for exporting development IPA file:

Calling the command will export a development IPA for the project defined in build_path . We put -allowProvisioningUpdates to allow updating the provisioning profiles generated by match before.

Wrapping it Together

We can put all the commands in a Fastlane’s lane as follows :

We can then call the lane from the command line, for example :

That’s it. Fastlane makes developing iOS builds much simpler than using it manually.

In the next post, we will talk about automating the binary distribution to beta distribution platform, as well as distribution to the Google Play and App Store. Stay tuned!

Chief Technology Officer at Joyseed Gametribe, a game developer based on Indonesia.