Integrate Fastlane to iOS project: Lesson 4

Create iOS build and upload to Crashlytics and Hockey app

Mark
3 min readSep 1, 2018

Last lesson, we use get_certificates and get_provisioning_profile action to download the certificates and profile for our iOS app. This time, we will use another action to build the .ipa and upload to Crashlytics and Hockey App.

In the upcoming lesson, I will assume your Project is named as Bookshop.

Create the build

Add build_app action to the lane in Fastfile as following.

Before that, I will create a new configuration named Adhoc in the project. Debug is used when building the app to your iDevices with connected cable. AdHoc is used when distributes the app via OTA(Over the Air services), such as Crashlytics and Hockey App. Release is used when upload the build to TestFlight and App Store.

Create a new Project Configuration named as Adhoc

After created the configuration, we also need to update the scheme. Create or update your project scheme, set the Run, Test to Debug, Profile, Analyze and Archive to Adhoc. (will create the Release in upcoming lesson).

I will name the scheme as Bookshop_dev_adhoc. That’s more understandable if you have multiple environment and project configuration.

Create/ Update project scheme

After that, update your lane inside your fastfile.

lane :build_app do
// get the production certificates from Apple Developer
get_certificates(
development: false,
force:false,
username: <your_apple_id>,
team_name: <your_team_name>,
filename: <you_file_name>,
output_path: "fastlane_delivery/dev/adhoc/"
)

// get the production certificates from Apple Developer
get_provisioning_profile(
adhoc: true,
app_identifier: <your_app_id>,
username: <your_apple_id>,
output_path: "fastlane_delivery/dev/adhoc",
provisioning_name: <your_provisioning_proflie_name>
)
// build the app
build_app(
scheme: "Bookshop_dev_adhoc",
workspace: "Bookshop.xcworkspace",
clean: true,
configuration: "AdHoc",
build_path: "fastlane_delivery/dev/adhoc/",
archive_path: "fastlane_delivery/dev/adhoc/bookshop_dev_adhoc",
derived_data_path: "fastlane_delivery/dev/adhoc/",
output_directory: "fastlane_delivery/dev/adhoc/"
)
end

You can use fastlane action build_app to check the detail of the parameter. One of the careful points is archive_path, it needs to give the name of the .archive file. If you just enter fastlane_delivery/dev/adhoc, you .archive file will be named as adhoc.archive and in dev folder.

Now, run bundle exec fastlane ios build_app. You will get your .ipa in fastlane_delivery/dev/adhoc/ directory.

Upload build and dSYM to Crashlytics

Add the following code to your lane.

// upload the build to Crashlytics
crashlytics(
api_token: <your_api_token>,
build_secret: <your_build_secret>,
ipa_path: "fastlane_delivery/dev/adhoc/Bookshop_dev_adhoc.ipa",
notes: <your_release_note>,
notes_path: <your_release_note_path>,
emails: <tester email, separated by commas>,
groups: <crashlytics_beta_group_name, separated by commas>,
notifications: <true or false>
)
// upload the dSYM to Crashlytics
upload_symbols_to_crashlytics(
dsym_path: "./fastlane_delivery/dev/adhoc/Bookshop_dev_adhoc.app.dSYM.zip",
api_token: <your_api_token>,
platform: "ios"
)

You can find the api token and build secret by following steps.

  1. Login to https://fabric.io
  2. On top right hand concern, click “Settings”
  3. click “Organizates”
  4. select the organizate you are in
  5. click “API Key” and “Build Secret” under your organizate name

Run your lane and test it.

Upload build and dSYM to Hockey App

Add the following code to your lane.

hockey(
api_token: <your_api_token>,
ipa: "fastlane_delivery/dev/adhoc/Bookshop_dev_adhoc.ipa",
dsym: "./fastlane_delivery/dev/adhoc/Bookshop_dev_adhoc.app.dSYM.zip"
)

You can add more parameters in your case if you want to notify and send the email to testers.

You can create the api token by following steps.

  1. Login to https://www.hockeyapp.net
  2. On top right hand concern, click your profile icon
  3. select “Account Settings” in drop down menu
  4. select “API Tokens” on left hand side menu
  5. enter the needed information in “Create API Token” session. You can select “Upload Only” in this case if you just want to upload the app”

Run your lane and test it.

What’s next?

Next lesson, we will introduces environment management by using Fastlane. How can we manage the different values in different environment by using Fastlane settings.

--

--