- Info
- Initialization
- Appfile
- Fastfile
- General functions and variables
- Matchfile (iOS only)
- Gemfile (iOS only)
- Pluginfile (iOS only)
The Fastlane can help you really much with sharing your current progress with testers. So, I suggest to integrate it to every new projects and do it on early beginning. And with this tutorial it should not create any problems for you. Depends of platform that you are working on there a little different steps. But in any case to start using the Fastlane you should have it installed on your machine. To do it check this document please.
If you already have the Fastlane installed just do
fastlane init
in your project root folder. Depends of platform it will ask you some questions like 'package name' or 'Apple Store ID'. After you finished with this wizard you should see success message as last message in terminal. You also will see that 'fastlane' folder was created.
In the 'fastlane' folder you will find a 'Fastfile' and 'Appfile'. These two are basic Fastlane files that did main magic. In the 'Appfile' you have main keys like:
for iOS
app_identifier "app_identifier" # The bundle identifier of your app
apple_id "[email protected]" # Your Apple email address
team_id "example_team_id" # Developer Portal Team ID
and for Android
json_key_file "" # Path to the json secret file - Follow https://github.com/fastlane/supply#setup to get one
package_name "com.example" # e.g. com.example.app
As you can see the 'Appfile' is really simple. And it doesn't have nothing interesting.
The 'Fastfile' is more complex and have a lot of autogenerated code right after init. You should know that it is written on Ruby and have required fields and structure.
fastlane_version "2.17.1" #the version of fastlane with what it was generated/updated.
default_platform :android # Setting default platform. In one file can be several platforms.
platform :android do # The Platform is required block of codes. By default Fastlane support :android, :ios, :mac
before_all do
# something here
end
desc "It's just an comment for lane (function)"
lane :beta do
version_code = update_build_number_android
gradle(task: "assembleRelease")
post_to_crashlitics
post_to_slack(platfrom: "Android", build_number: version_code)
end
desc "Deploy a new version to the Google Play"
lane :deploy do
gradle(task: "assembleRelease")
supply
end
after_all do |lane|
# This block is called, only if the executed lane was successful
end
error do |lane, exception|
# And this if some errors
end
end
Main thing that you should know is that 'lane' is like a function and it should be in 'platform' like in class. You can have any amount of lanes in your files and all of them can be called from terminal by name.
Next you can find general Fastfile for iOS platform. Usually you can just copy this code and past into your fresh generated Fastfile.
fastlane_version "2.48.0"
default_platform :ios
platform :ios do
import_from_git(
url: "[email protected]:rozdoum/fastlane_general_lanes_for_mobile.git",
branch: "HEAD",
path: "GeneralLanes"
)
#If you need different settings please uncommetn and define
#FABRIC_API_TOKEN = ""
#FABRIC_BUILD_SECRET = ""
#FABRIC_DEFAULT_EMAIL = ""
#SLACK_URL = ""
SLACK_CHANNEL = ""
before_all do
ENV["SLACK_URL"] = SLACK_URL
cocoapods
end
desc "Submit a new Beta Build to Crashlytics"
desc "This will also make sure the profile is up to date"
lane :beta do |values|
match(type: "development", readonly: true) # more information: https://codesigning.guide
build_number = update_build_number_ios(plist_path: "./ProjectName/Info.plist")
gym(scheme: "ProjectName", export_method: 'development') # Build your app - more options available
post_to_crashlitics
post_to_slack(platfrom: "iOS", build_number: build_number)
end
desc "Submit a new Beta Build to Apple TestFlight"
desc "This will also make sure the profile is up to date"
lane :uploadToTestFlight do
match(type: "appstore", readonly: true) # more information: https://codesigning.guide
gym(scheme: "ProjectName", export_method: 'app-store') # Build your app - more options available
pilot
# sh "your_script.sh"
# You can also use other beta testing services here (run `fastlane actions`)
end
desc "Deploy a new version to the App Store"
lane :release do
# match(type: "appstore")
# snapshot
gym(scheme: "ProjectName") # Build your app - more options available
deliver(force: true)
# frameit
end
end
And same for Android. Usually you can just copy this code and past into your fresh generated Fastfile.
fastlane_version "2.17.1"
default_platform :android
platform :android do
import_from_git(
url: "[email protected]:rozdoum/fastlane_general_lanes_for_mobile.git",
branch: "HEAD",
path: "GeneralLanes"
)
#If you need different settings please uncommetn and define
#FABRIC_API_TOKEN = ""
#FABRIC_BUILD_SECRET = ""
#FABRIC_DEFAULT_EMAIL = ""
#SLACK_URL = ""
SLACK_CHANNEL = ""
before_all do
ENV["SLACK_URL"] = SLACK_URL
end
desc "Submit a new Beta Build to Crashlytics Beta"
lane :beta do
version_code = update_build_number_android
gradle(task: "assembleRelease")
post_to_crashlitics
post_to_slack(platfrom: "Android", build_number: version_code)
end
desc "Deploy a new version to the Google Play"
lane :deploy do
gradle(task: "assembleRelease")
supply
end
end
- Go to project_name/app folder and create file (Resource bundle in android studio) 'version.properies' and copy/paste this code:
#Fri Nov 10 15:22:46 EET 2017
VERSION_NAME=1.0
VERSION_CODE=1
- Go to project_name/app/build.gradle and add this changes.
As you can see in the Fastfile I use import_from_git function. When you will run any lane from this Fastfile it will try to checkout the GeneralLanes file and all lanes from it will be added to the main Fastfile.
Next you can see five variables. Most of them are commented.
#If you need different settings please uncommetn and define
#FABRIC_API_TOKEN = ""
#FABRIC_BUILD_SECRET = ""
#FABRIC_DEFAULT_EMAIL = ""
#SLACK_URL = ""
SLACK_CHANNEL = ""
These variables defined in the GeneralLanes file. But you can redefine every of them. Ask organization admin for the FABRIC_API_TOKEN and FABRIC_BUILD_SECRET values. The FABRIC_DEFAULT_EMAIL is a list of emails on what the build will be shared by default.
Set slack url of your organization to the SLACK_URL field to post a message.
And finally the SALCK_CHANNEL. You should define a Slack channel in what the messages should be send. Just fill in channel name like "#exampleChanelName" and this channel will receive messages. You also can send direct messages if you set "@exampleUser" for example.
Currently in the GeneralLanes file we have these lanes:
update_build_number_android
This will increment the build number and return it as result. But to it work you also need to update your build.gradle file. I will describe how to do it later.
update_build_number_ios
This will just increment a build number variable in Info.plist file and return it as result. You need to provide path to your Info.plist file as attribute.
post_to_crashlitics
If you want to post new build to the Crashlitics this lane for you. You can call it without any attribute.
post_to_slack
This will push message to the Slack channel. To use this lane please add attributes:
- platfrom - required. Simple "iOS" or "Android"
- build_number - required. Usually it is what the
update_build_number
returned. - message - optional. Just add any additional message if you need.
register_new_device (iOS only)
This will register new device and add it to the provision.
Usage: just run the command, it will ask you for the Device Name and UUID.
renew_profiles (iOS only)
Recreate the provisioning profiles so you can deploy to your device, release on fabric and push to app store.
It is required additional plugin remove_provisioning_profile. To install it use - fastlane add_plugin remove_provisioning_profile
Usage: run it without parameters and it will remove the Development profiles. Or add type:app-store for single profile or types:[app-store, development] for multiple profiles.
load_provisions_and_certificates (iOS only)
This will load stored provisions (development and appstore) and certificates.
Usage: just run the command for loading stored provisions.
In the 'fastlane' folder create 'Matchfile' with the following content:
for iOS
git_url "ssh://ios-certificates.git"
git_branch "git_branch"
type "development" # The default type, can be: appstore, adhoc or development
app_identifier CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)
# username "[email protected]" # Your Apple Developer Portal username
In the root folder create 'Gemfile' with the following content:
for iOS
source "https://rubygems.org"
gem 'cocoapods'
gem 'fastlane'
plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
eval_gemfile(plugins_path) if File.exist?(plugins_path)
for iOS
gem 'fastlane-plugin-remove_provisioning_profile'
After this run command
fastlane install_plugins
and commit 'Pluginfile', 'Gemfile' and 'Gemfile.lock'