How to build applications using Fastlane
Published in
3 min readJan 13, 2023
Preparation
First of all, you will need to have Brew, Ruby, and Fastlane on your machine, follow those steps if you haven’t yet:
Local Machine preparation
Install Brew:
- Visit https://brew.sh/ to see installation details.
Install Ruby and Fastlane by the following commands:
- Ruby:
brew install ruby
- Fastlane:
brew install fastlane
Configure Stores
Before you can publish your application build, you will need to set up stores to provide a build that will be published to the beta or even to production.
- Make sure that both projects in (AppStore Connect) and (Google Play Console) for every environment are created and configured.
- Create a repository for iOS Certificates and Provision Profiles.
Project
- Create file named
Gemfile
in the root of your project - Add needed gems
Android settings
. After you have created apps in google play console for every of your environment, you need to fill in all required information. With out this information you can not upload build. This is list of information you need to fill in:
Android prod & stage info needed:
- App name
- Short description
- Full description
- App icon
- Feature graphic
- Phone screenshots
- Countries anabled
- Terms & conditions link
- Generate you JSON key data to have ability to upload build to google play. How to do this you can find here
- https://docs.fastlane.tools/getting-started/android/setup/#collect-your-google-credentials. Go through all steps!
- Remember, that first build you need to upload using google play console, because we need to have at least one build with selected package name in google play before automatic uploading with fastlane.
IOS settings
- Create API Key for App Store Connect API.
Take a look at this article: https://developer.apple.com/documentation/appstoreconnectapi/creating_api_keys_for_app_store_connect_api. - Go to Apple developer program (https://developer.apple.com) =>
Account
=> authorize =>App Store Connect
=>Apps
=> Press plus button and add as may applications as many env files you have (be sure you use the same bundle identifiers that you specified in your env files)
Configure Fastlane
- Create a folder
fastlane
in the project root with a single fileFastfile
then add these lines to it:
- Create env files for every environment at the root of your project. For example
.env.prod
etc. - Put variables to env files to connect App Store API Key, checkout certificates and fill in all information, like here:
- Run command
bundle exec falstlane ios build_and_testflight --env prod
to generate certificates and provisions for a production build. - To continue with IOS and Android, go to
Fastfile
in root of your project and update it
- and update your env file
- Of course, you may want to inform your team that new release is come out. To do that you can integrate slack connection. All you have to do are:
- Add new section to your
.env
files
- Add new lane to your
Fastfile
(for exampleslack_connect
) and call it in yourbuild_and_testflight
andbuild_and_playmarket
lane afterupload_to_testflight()
andupload_to_play_store()
.
- And if you want to handle errors and get information about them in slack, just add
on_error
def to yourFastfile
and use in on catch error
- And call it right after
build_and_testflight
andbuild_and_playmarket
lanes.
error do |lane, exception|
on_error(exception)
end
- That is it!