Managing the publishing new versions of beta applications can be a pain. You must remember about updating the version’s number, setting up the right target or choosing specific emails from the list on Fabric. It’s easy to forget about one of these things when the newest version of the app is ready. That’s why I decided to use the fantastic Fastlane tool which enabled me to fully automate those actions.
In this article, I am going to describe how to configure this tool so that you can implement Fastlane in your project by yourself. We’re going to add a fastfile file, which we’ll use to automatically upgrade the app’s version, generate the build and share it with Fabric. Additionally, it will push a new commit informing about a new version. Let’s start!
-
Installing Fastlane
To install Fastlane, you need to execute the command in the terminal:
1 |
sudo gem install fastlane -NV |
After successful installation, you’ll get the message:
-
Preparing the project for installation
When building Fastlane, you’ll use the ready-made actions defined in Fastlane. Some of them require an appropriate preparation of your project.
To enable automatic upgrade of the project’s version, you need to switch on avgtool
You need to go to the Build Settings tab in the target, then search for the ‘versioning’ phrase.
Then set up:
– Current Project Version na 1 (or other value)
– Versioning System na Apple Generic
Additionally, the graphics have to be in A.B.C. format
Let’s remember here about the correct setting of the provisioning profile. A good way of sorting out the signing of the app versions is adding separate targets to the ad-hoc versions and App Store.
-
Initializing Fastfile
You begin the project integration with Fastlane by creating a fastfile file. You then get to the main folder of your project in the terminal and then use the command:
1 |
fastlane init |
The configuration starts with the question whether you want to use one of the ready-made templates:
However, you’re configuring the project yourself, so you use the option number 4. After a while, there will display a message about the successful configuration of Fastlane. Additionally, you need to confirm a few tips by clicking the enter button.
Now, the project should like this:
You probably noticed that apart from the fastlane folder, in which there are Appfile and Fastfile files, the configurator generated also 2 Gemfile files. They are used to manage versions so that everyone who works on the same project will use the same versions of gems.
In this article, we will skip this stage (if you’re interested, there’s a link to the documentation: https://bundler.io) and get straight to Fastfile.
-
Configuring fastfile
Let’s open our freshly generated fastfile using the editor. I recommend the free Visual Studio Code program to which you can install an iOS Common Files (link: https://marketplace.visualstudio.com/items? itemName=Orta.vscode-ios-common-files) plugin which automatically chooses the language and colors the syntax.
Fastfile consists of the so-called lanes. In the simplest terms, a single lane can be understood as a function in which actions are taken in a row. Let’s define a few global variables which will make it easier to take actions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#Globals prefix_dir = "./" project_name = "YOUR_PROJECT_NAME" project_dir = "#{prefix_dir}#{project_name}/" project_scheme = "#{project_name}" project_output_name = "#{project_scheme}_AdHoc" xcodeproj = "#{prefix_dir}#{project_name}.xcodeproj" workspace = "#{prefix_dir}#{project_name}.xcworkspace" build_dir = "./build" #Crashlytics crashlytics_api_token = "YOUR_CRASHLYTICS_API_TOKEN" crashlytics_build_secret = "YOUR_CRASHLYTICS_BUILD_SECRET" crashlytics_emails = [EMAILS_SEPARATED_BY_COMMAS] |
The texts written with Caps Lock need to be filled in according to their description. Thanks to variables defined this way, we keep the order and readability of our code. Additionally, all generated builds will be saved in a separate build folder which will be created later on.
-
Creating lanes
Let’s create a few lanes responsible for minor functionalities and then connect them into one (it will be responsible for building and sharing a new version on Fabric). Let’s start with putting a higher number of the version and build.
Thanks to the earlier preparation of the project, we’ll use ready actions (url: https://docs.fastlane.tools/actions/).
1 2 3 4 |
lane :increment_build_and_version_numbers do increment_build_number increment_version_number end |
As you can see, it’s a piece of cake. We used ready actions which do all the work for us.
It’s now time to use a lane responsible for archiving ad-hoc versions. To do this, we’ll use a properly configured build_app action. Additionally, we’ll check if a build folder exists, and if not, we’ll create it.
1 2 3 4 5 6 7 8 9 10 11 12 |
lane :archive_adhoc do Dir.mkdir("../#{build_dir}") unless File.exists?("../#{build_dir}") build_app( scheme: project_scheme, output_name: "#{project_output_name}", workspace: workspace, configuration: "Release", export_method: "ad-hoc", output_directory: "#{build_dir}" ) end |
Let’s now add another lane, this time one responsible for sharing versions through Fabric and sending dSYM files. Let’s remember to complement earlier global variables with the keys to Crashlytics.
1 2 3 4 5 6 7 8 |
lane :upload_to_crashlytics do crashlytics( api_token: crashlytics_api_token, build_secret: crashlytics_build_secret, emails: crashlytics_emails ) upload_symbols_to_crashlytics(dsym_path: "#{build_dir}/#{project_output_name}.app.dSYM.zip") end |
The last step will be to send the commit with a tag informing about the version number.
1 2 3 4 5 6 7 8 9 |
lane :commit_beta_version do version = get_version_number( target: project_scheme, xcodeproj: xcodeproj, ) sh "git commit -am 'Fabric Beta version: #{version}'" sh "git tag -a v#{version} -m 'Fabric Beta'" sh "git push" end |
The lanes we created are ready to be used. Let’s add the last one, which will launch then all.
1 2 3 4 5 6 |
lane :fabric_beta do increment_build_and_version_numbers archive_adhoc upload_to_crashlytics commit_beta_version end |
A fastfile file created this way will enable us to generate a new build and share it on Fabric.
-
Launching
To launch the lane we created, let’s go again to the main folder of our project in the terminal. Let’s execute:
1 |
fastlane fabric_beta |
The whole process may take a while (after all, we’re creating an application). However, if we configured the project properly and filled in data in globals, at the end, we should get a message about the successful generation of a version
Congratulations! You just created a new version of your app, shared it with selected email addresses through Fabric and sent a commit informing about the increased version number. And all that using just one command!
You can download final fastfile from:
https://github.com/Appchance/automate-fabric-beta-distribution-with-fastlane
You might also like

Increasing mobile app retention focuses on the users returning…

Most marketing and e-commerce experts agree that m-commerce applications…

The number of people shopping through mobile devices is…

There has been much talk of e-commerce in recent…

App Store Optimization, or ASO, entails the process of…