Hello! In this article, I will provide you with information about the basic features of Fastlane and then guide you through the process of integrating Fastlane into your Android applications with some practical exercises. Are you ready to get started?
If you’ve ever distributed an iOS or Android app to the App Store or Google Play Store, you know how tedious the process can be.
To actually distribute your application to the App Store or Google Play Store, you have to interact with various platforms such as Apple Developer Console, App Store Connect, and Google Play Console. However, both platforms have their own APIs, and you can interact with these APIs programmatically. Therefore, theoretically, you can create a script to interact with all these services and distribute your application almost automatically.
Fastlane operates locally, interacting with your app’s code, Xcode or Gradle configurations, metadata, and other crucial data like private keys. It takes all this information and interacts independently with the APIs of the various services required to automate your distribution process. This way, it speeds up and simplifies your deployment process.
If I wanted to express what I wrote about Fastlane in a diagram, the diagram would look like the following.
Let's integrate Fastlane into an Android application using React Native.
Are you ready? It's time to publish your Android application with React Native and Fastlane!
Before installing Fastlane, you should check your Ruby version because Fastlane supports Ruby versions 2.5 and above. You can use the following command to check your Ruby version:
$ ruby --version
If your Ruby version is below 2.5 or if Ruby is not installed, you should install Ruby version 2.5 or higher on your computer.
In this article, one term you'll frequently encounter is Bundler. So, what is Bundler? Let's explain briefly: Bundler is a dependency management tool used in Ruby projects. It ensures that all gems (Ruby libraries) and their versions are managed consistently so that there are no incompatibilities between the libraries used in the project. This ensures that tools like Fastlane run with the correct versions.
Leveraging Bundler and Gemfile when using Fastlane makes it clear which version of Fastlane and which dependencies you will use.Additionally, this method speeds up the execution process of Fastlane. Use the following code to install Bundler.
$ gem install bundler
Run the "bundle init" command under the "android" folder of your project to create your Gemfile.
$ bundle init
As a result of this command, a Gemfile will be created in your project. This Gemfile is a configuration file that defines the dependencies of your Ruby project and specifies how these dependencies should be installed.
After these steps, install Fastlane on your computer with the following code.
$ brew install fastlane
Once Fastlane is installed on your computer, run the following command to add Fastlane to your project.
$ fastlane init
The command "fastlane init" creates a starting point for Fastlane integration into your project and prepares your Fastfile. By editing this file, you can define your automation tasks. The "fastlane init" command will ask us for the following information.
Enter the package name of your application.
Fastlane requires a JSON file that can be obtained from the Play Console. This file is used to update metadata and upload new versions. Press enter when asked for the path to your JSON secret file.
When asked if you plan to upload information to Google Play through Fastlane, respond with 'n' (we can set this up later).
After entering this information, your Fastlane configuration will be set up, and you will see the following output.
After successfully running the "fastlane init" command, a configuration is automatically generated based on the provided information. As a result of this configuration, files will be created within your project. Let's now take a look at the appearance of the generated files in Visual Studio Code.
The fastlane directory containing the Appfile and Fastfile files will be created, as seen in Visual Studio Code. So, what are these Appfile and Fastfile files for?
Appfile: The Appfile typically contains information such as the application's package ID (bundle ID), the name of the application, and credentials for a Google Play or App Store account. This information is necessary for Fastlane to interact with these accounts and distribute your app.
Fastfile: Within the Fastfile, a series of tasks can be defined, such as distribution processes, running tests, generating screenshots, updating version numbers, and more. These tasks contain specific steps or commands and, when executed by Fastlane, perform a particular operation.
After integrating Fastlane into our project, the first step is to sign the APK with a private key. The APK is used for distributing our Android application. This file contains all the code, resources, and other necessary files of the application. This private key is stored in a keystore file. You can create this keystore file using the keytool in the terminal with the following command:
$ keytool -genkey -v -keystore sampleappforfastlane-key.keystore
-alias sampleappforfastlane-key-alias -keyalg RSA -keysize 2048 -validity 10000
After running this code, it will ask us for some information.
After the key is created, we need to create an env file and enter some information into this env file.
We need to open the android/app/build.gradle file and add our keystore configuration.
After configuring our keystore, we can create our apk file. To do this, we first need to go to the android directory and run the ./gradlew assembleRelease code. This code will create the app-release.apk file under the android/app/build/outputs/apk/ directory. You can distribute your application by uploading this file to the Google Play Store and making the necessary configurations in the Google Play Store.
To avoid performing these steps for every new version, we can start filling out our Fastfile file 🚀
The code I have written here defines a task (lane) to upload an alpha version of a React Native application running on the Android platform to the Google Play Store using Fastlane.
Let's take a closer look at the code snippet I've written and analyze it in more detail.
The platform :android block specifies that this workflow is only applicable for the Android platform.
The lane :alpha block defines a workflow named alpha. This workflow is used to upload the alpha version of the application to the Google Play Store.
increment_version_code: This step increments the version code of the application. It is typically a number that is increased with each new release. This step updates the version code in the ./app/build.gradle file. To use this block, you need to run the bundle exec fastlane init command.
gradle(task: "assembleRelease"): This step compiles and packages your app into an APK file by running the ./gradlew assembleRelease command. This command converts the compiled version of the application into a signed and ready-to-distribute APK file.
supply: This step uploads the generated APK file to the Google Play Store. The track parameter specifies which distribution channel (for example, alpha, beta, or production) the APK will be uploaded to. The apk parameter specifies the path to the uploaded APK file.
As we conclude, it's worth summarizing the key benefits of using Fastlane. There are many advantages of using Fastlane. First of all, Fastlane saves you time thanks to automated workflows. It also minimizes the problems that can arise from manual processes and errors, thus providing a more reliable and error-free deployment process. These advantages can significantly streamline your developer processes.
After learning about the features of such a fantastic service and how to leverage it, diving into Fastlane's convenience and advantages will be a delightful experience! 🥳 Make sure to give it a try!
Ceyda is a passionate AWS certified developer with a keen interest in next generation technologies. She consistently seeks innovative solutions by integrating the latest advancements in cloud computing and modern application development.
We believe in the power of technology when it comes to success. We help our clients to keep up with the best practices in technology for their custom business needs while improving the way they work.
We use cookies to offer you a better experience with personalized content.
Cookies are small files that are sent to and stored in your computer by the websites you visit. Next time you visit the site, your browser will read the cookie and relay the information back to the website or element that originally set the cookie.
Cookies allow us to recognize you automatically whenever you visit our site so that we can personalize your experience and provide you with better service.