Robust React Native App — 4.1
In this section, our focus is on Fastlane — a tool facilitating the automated publication of our app on the Google Play Store. The goal is to streamline all necessary processes through Fastlane. Within this post, I’ll elaborate on automating the release and Alpha processes for an Android application.
Before Starting Article
Before diving into this article, I embarked on a journey after my initial piece. I transitioned from a mere concept to crafting a tangible product, leveraging the insights gained from previous articles. My app is designed to facilitate the enhancement of English reading and writing skills by enabling users to engage with English articles.
Subsequently, my articles will be closely tied to the development and progress of my app. I’ll share the challenges encountered and the solutions devised along the way. If you’re interested in trying out my app, you can download it using the following link.
Getting Started
Before installing Fastlane, ensure that you have the latest Xcode command line tools installed. After confirming this, proceed with the installation of Fastlane ⬇️.
brew install fastlane
Once you’ve installed Fastlane globally, navigate to your project directory. Before implementing Fastlane for Android, it’s crucial to gather specific prerequisites. Your Android app must have been published at least once before you can automate the process.
Gathering Your Google Credentials
cd android
fastlane init
It will prompt you for the package name, which should match your package ID. If you’ve forgotten it, you can find it in yourAppfolder/Android/app/build.gradle.
Once prompted, provide the path to the JSON secret file you downloaded (the Google Credentials). After downloading the file, place it under yourapp/android/fastlane folder.
Afterward, it will request to download existing metadata and set up metadata management (y).
Upon successful completion, it will prompt you to execute the Fastlane test.
Congratulations! Your Fastlane has been initialized, generating some necessary files.
And Fastlane created a fastfile
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
default_platform(:android)
platform :android do
desc "Runs all the tests"
lane :test do
gradle(task: "test")
end
desc "Submit a new Beta Build to Crashlytics Beta"
lane :beta do
gradle(task: "clean assembleRelease")
crashlytics
# sh "your_script.sh"
# You can also use other beta testing services here
end
desc "Deploy a new version to the Google Play"
lane :deploy do
gradle(task: "clean assembleRelease")
upload_to_play_store
end
end
Let’s check, is it working well?
run, make sure you are in the Android directory
Initial run Fastlane
fastlane test
If no errors occur, you have successfully initialized Fastlane. Next, remove all lines in the Fastfile and add a plugin for versioning purposes.
fastlane add_plugin versioning_android
then Update your fast file like below
First lane and upload to Closed Test Alpha
desc "Upload to Closed Test Alpha Track"
lane :upload_to_closed_test_alpha do
# gradle(task: 'clean')
android_set_version_code(
gradle_file: "app/build.gradle" # optional
)
gradle(
task: 'clean bundle',
build_type: 'Release',
print_command: false,
)
upload_to_play_store(
track: "alpha",
skip_upload_apk: true,
aab: lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH])
end
run into the terminal
fastlane upload_to_closed_test_alpha
Here we’ re, we accomplished a significant milestone by successfully uploading our app using Fastlane. We initiated a Closed Testing Load — an essential step in our process.
Now, let’s delve into the intricacies of what we accomplished and explain the steps taken to achieve this
desc "Upload to Closed Test Alpha Track"
Description of the lane
lane :upload_to_closed_test_alpha do
Fastlane operates with lanes that automate a sequence of commands. Essentially, a lane represents a predefined series of commands. These lanes can vary, including ones like release, develop, and test, each serving different purposes in the automation process.
android_set_version_code(
gradle_file: "app/build.gradle" # optional
)
This command is an extension within Fastlane that handles the incrementation of the Android version code. Without utilizing this extension, manually updating the version code becomes a necessity each time you deploy your app to the Play Store.
gradle(
task: 'clean bundle',
build_type: 'Release',
print_command: false,
)
This is a Gradle task responsible for generating AAB (Android App Bundles) and executes a sequence of actions by first cleaning the project and then initiating the build process.
upload_to_play_store(
track: "alpha",
skip_upload_apk: true,
aab: lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH])
This task is designed for uploading to the Play Store. The “track” parameters determine the release track to which the app is targeted, such as alpha closed test, beta open test, or the general rollout release.
abb: lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH])
That line gives the location of the generated abb file.
let’s run the fastlane lane,
fastlane upload_to_closed_test_alpha
Second lane upload to Release
To switch the value of the “track” parameter from “alpha” to “rollout” in the upload_to_play_store
command, make the following adjustment: That's it!
upload_to_play_store(
track: 'rollout'
)
This change will target the “rollout” track for the upload process.
# Release
desc "Upload to Release Track"
lane :release do
# gradle(task: 'clean')
android_set_version_code(
gradle_file: "app/build.gradle" # optional
)
android_set_version_name()
gradle(
task: 'clean bundle',
build_type: 'Release',
print_command: false,
)
upload_to_play_store(
track: 'production',
skip_upload_apk: true,
aab: lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH])
end
Find Me 👤
LinkedIn:
https://www.linkedin.com/in/s%C3%BCha-i%C5%9F%C4%B1k-92b251101/
GitHub:
https://github.com/abdullahsuhaisk/
About Sisal Digital Hub Türkiye
LinkedIn:
https://www.linkedin.com/company/sisal-digital-hub-t%C3%BCrkiye/mycompany/verification/
Medium Page:
https://www.linkedin.com/company/sisal-digital-hub-t%C3%BCrkiye/mycompany/verification/