Build the app with Fastlane
Introduction
Last week we discussed how to setup Fastlane. This week we’re going to be doing the first step in many workflows, building the app. Building the app is what you’re used to doing in Xcode, by pressing Command + R or Command + B, but when we’re talking about building the app from the command line, with whatever configuration we want, we’re talking about Fastlane.
The Fastfile
This will be the first time in this series that we’re going to be looking at the Fastfile. The Fastfile is the file that contains all the lanes that you can run. A lane is a set of commands that you can run. We have had one before, when we looked into auto-bumping SPM versions, but we’re going to start from scratch here.
Let’s start with the basics:
#!/usr/bin/ruby
# frozen_string_literal: true
fastlane_version '2.225.0'
default_platform :ios
platform :ios do
This is the basic setup of a Fastfile. We’re setting the fastlane version and the default platform. We’re also specifying that we’re going to be working with iOS. Any new lanes or commands that we add will be added below this. Like we mentioned before, we can also import any other Fastfiles we have, but we’re not going to do that here. Let’s keep it nice and simple!
Building the app
We’re going to be using the incredibly powerful gym
action to build the app. This action is going to build the app and create an .ipa
file that we can use to distribute the app.
desc "Build the app"
lane :build do
gym
end
This will just do the bare minimum, and if you run it you might actually see a failure because some things are not set up, or more importantly, this will still require your input when run, which is not something we want when we’re writing automations. We want these lanes to be able to run entirely on their own, either on our machine, or on a CI/CD provider (foreshadowing?!). The complete list of parameters is available here, but we’re going to be looking at a few of them here.
The scheme
parameter
This is the name of the scheme that you want to build. This is the same as the scheme you would select in Xcode when you’re building the app.
desc "Build the app"
lane :build do
gym(scheme: "MyApp")
end
The configuration
parameter
This is the configuration that you want to build the app with. This is the same as the configuration you would select in Xcode when you’re building the app. The default value is Release
desc "Build the app"
lane :build do
gym(scheme: "MyApp", configuration: "Release")
end
The export_method
parameter
This is the method that you want to use to export the app. This is the same as the method you would select in Xcode when you’re exporting the app. For most iOS apps, if you plan on later on submitting to TestFlight or the app store, you would use app-store
.
If you’re building an SPM package, you’d use package
. The options available are: app-store
, validation
, ad-hoc
, package
, enterprise
, development
, developer-id
and mac-application
desc "Build the app"
lane :build do
gym(scheme: "MyApp", configuration: "Release", export_method: "app-store")
end
The output_directory
parameter
This is the directory where the .ipa
file will be saved. The default value is ./output
desc "Build the app"
lane :build do
gym(scheme: "MyApp", configuration: "Release", export_method: "app-store", output_directory: "./build")
end
The complete Fastfile
#!/usr/bin/ruby
# frozen_string_literal: true
fastlane_version '2.225.0'
default_platform :ios
platform :ios do
desc "Build the app"
lane :build do
gym(scheme: "MyApp", configuration: "Release", export_method: "app-store", output_directory: "./build")
end
end
## Conclusion
This is it! This is the complete Fastfile that will build your app. You can run this lane by running bundle exec fastlane build
in the terminal. This will build the app, and save the .ipa
file in the ./build
directory.
That is the first step in so many of the automation steps that we’re going to be looking into in the future, and we will be doing a lot of customization to this lane in the future.
Let me know if you have any questions, or if you want me to cover anything in particular in the future. I’m always looking for new ideas!