Infrastructure as Code Best Practices with Terraform for DevOps
João Victor Alhadas | Dec 17, 2024
We live in a highly dynamic tech landscape where new versions of applications are released daily to introduce new features, fix bugs, enhance user experience, and ultimately, increase product quality and stand out in app stores.
With this comes a challenge: how can the release of new versions be automated to speed up the distribution process of these applications?
There are several points related to the app distribution chain that make the process quite complex and filled with challenges.
The wide variety of platforms and smartphone versions require a different approach. Each platform has complex configurations necessary for its execution and its own method of application signing, which is crucial for information security since sensitive data is used for this purpose.
The variety of programming languages is also an important point to consider. Developers can build applications with a wide variety of languages like Java, Kotlin, Swift, Objective-C, React Native, Flutter, and many more.
Plus, to follow best practices, it’s necessary to have a production environment and environments for testing and validation, such as the development environment and user acceptance testing environment. Configuring and managing the app stores is also necessary so that application versions are released correctly.
And, of course, you have to do all of this quickly to stay competitive in the market. That’s a lot to juggle!
Thankfully, there are clever solutions that can help tackle these challenges. In this article, we’ll explore how Fastlane can help developers automate and streamline the mobile app deployment process, ensuring continuous and reliable delivery.
Fastlane is a powerful and flexible automation tool designed to simplify the process of developing, testing, and deploying mobile applications. Quickly becoming a popular choice among iOS and Android developers, Fastlane reduces the repetitive and error-prone workload associated with the app development lifecycle.
Fastlane’s key features include:
If that impressive list of features isn’t enough to convince you to try out Fastlane, here’s a few more reasons:
To use Fastlane, you need to have a few prerequisites:
Some Fastlane plugins and actions allow the app to be configured on the Google and Apple stores.
However, in this article, we’ll assume that the apps are already configured. Since this task is usually performed once, it’s often done directly in the store.
Fastlane is a highly flexible tool that allows you to create custom scripts to meet the specific needs of each case.
Before we proceed with the instructions, it’s important to highlight some key concepts of automation scripts:
In the following sections, we will demonstrate the main commands that can be executed to start the process of creating scripts and automating processes.
Here’s how you can use Fastlane for Android applications.
Before you begin, make sure you have Fastlane installed on your system. If you haven’t installed it yet, you can follow the installation instructions in the official Fastlane documentation: Fastlane Setup Documentation.
Open a terminal in the root directory of your Android project and execute the following command to start the Fastlane setup wizard:
$ fastlane init
This command will initialize Fastlane in your project and guide you through the setup process.
Provide your application’s package name so Fastlane can create the automation process tailored to the corresponding app.
This step is optional. If you intend to use Fastlane for tasks beyond distribution, such as automatic screenshot uploads, it’s important to follow this step. We won’t be doing this in the example below, so we’ll skip this step.
Fastlane will generate two essential files: Appfile and Fastfile.
The Appfile will store important information about the app, like the package name and the path to the Google Play API authentication file.
The Fastfile generated for the example app contains three suggested lanes:
Several actions are used within these lanes:
As observed in the previous step, Fastlane has already set up a basic standard script with some suggested tasks that can be executed. Now, you can tailor the file according to your needs. The Fastlane documentation provides a comprehensive list of all available actions and plugins for this purpose, along with examples of beta distribution and production deployment.
Once everything is set up, you can execute the automation using the fastlane command followed by the name of the created lane.
For example, if you want to execute the “beta” lane:
$ fastlane beta
Here’s the process for using Fastlane to automate iOS app releases.
Make sure to have Fastlane installed on your system. If not installed yet, you can follow the installation instructions in the official Fastlane documentation: Fastlane Setup for iOS.
Open a terminal in the root directory of your iOS project and execute the following command to start the Fastlane setup wizard:
$ fastlane init
The Fastlane wizard prompts you to choose the task to automate. In this case, we chose option two, which automates the distribution of beta versions to TestFlight, Apple’s beta testing platform.
Depending on your needs and how the project is structured, Fastlane may prompt you to choose which scheme to use in building the scripts.
In this example, we have three environments and will automate the distribution for the development environment. Of course, you can edit the scripts after running the wizard to expand to other environments.
Fastlane will request your Apple ID to connect to App Store Connect and the Apple Developer Portal. It’s important to use an Apple ID with access to the account where the apps you want to automate are located.
If the selected Apple ID has access to more than one account/organization, Fastlane will prompt you to select which account to use.
Just like in the Android setup, Fastlane will generate the same two files (Appfile and Fastfile) for iOS.
The Appfile will store important information about the app, such as the identifier, the Apple ID authorized to integrate with the store, the App Store Connect team ID, and the Developer Portal team ID.
The generated Fastfile for the example application is quite simple, with only one lane called “beta” where three actions are executed:
As mentioned in the previous step, the script file generated by Fastlane is quite simple and serves merely as a starting point. It should be tailored to meet the unique needs of each project, and you’ll likely want to incorporate various actions, such as Match, a plugin designed to streamline the creation and management of certificates and provisioning profiles.
The Fastlane documentation provides a comprehensive list of all available actions and plugins for this purpose, along with examples of beta distribution and production deployment.
Here, the process mirrors that described for Android — simply execute the automation using the fastlane command followed by the name of the created lane.
For example, if the lane is named “beta”:
$ fastlane beta
It’s important to note that plugins and actions are available on both platforms and can be used to craft the script with functionalities ranging from automating application versioning to sending notifications via Slack.
Actions require parameters for proper execution depending on the project and goals to be achieved, so it’s crucial to consult the documentation.
Once the scripts are created and customized, you can integrate them into the development cycle by incorporating them into CI/CD pipelines.
Installation of Ruby and Fastlane on the machines responsible for running the pipelines is necessary, and it’s worth remembering that machines with macOS must be available for executing iOS pipelines.
Companies and developers will always have one thing in common — they want to save time. Automating mobile application releases with Fastlane is an excellent way to do just that.
Fastlane not only speeds up the development and release process but also does so securely and consistently, thanks to a free, open-source tool.
This approach to mobile application releases helps keep things standardized and repeatable, saving time and money in the long term.
To learn more about improving your app development processes, have a look through the Cheesecake Labs blog, where our team members share insights and tips to help you create the best digital products and experiences.
And for companies intrigued by how we use Fastlane and other tools in our app development services, send us a message. We’d love to chat!
The guy from security, automation, camping, motorcycle, travel, and collaboration! Let’s talk?