LoginSignup
10
8

More than 5 years have passed since last update.

Crashlytics利用時のFastlane設定方法(iOS編)

Last updated at Posted at 2016-07-15

インストール

$ gem install fastlane

もしくは、Gemfileにgem "fastlane"と記入しbundle install

セットアップ

プロジェクトフォルダへ移動して以下のコマンドを打つ。

$ fastlane init

質問されるので適宜回答する。

Do you want to get started? This will move your Deliverfile and Snapfile (if they exist) (y/n)

使いはじめるか聞いてるのでyを押す。

Do you have everything commited in version control? If not please do so! (y/n)

バージョンコントロール使ってる?使ってなかったら使って!
使ってる状態ならy、使ってなかったらnを押して、使い始めたらyにして先に進む。

App Identifier (com.krausefx.app):

fastlaneを使いはじめるアプリのBundle Identifierを入力する

Your Apple ID (fastlane@krausefx.com):

自分のAppleIDを入力する。プロビジョニングプロファイルとか作れるアカウントだと嬉しいけど、ダウンロード出来るアカウントなら大丈夫。

Do you want to setup 'deliver', which is used to upload app screenshots, app metadata and app updates to the App Store or Apple TestFlight? (y/n)

アプリをAppStoreとかTestflightに上げるか聞いてる。

アクション

fastlaneが公式に用意している主なアクション(コマンドラインツール)は以下の通り。

カスタムアクションを作ることも可能。

  • deliver : スクリーンショット、メタデータ、アプリをApp Storeにアップロード
  • snapshot : アプリのスクリーンショット撮影を自動化
  • frameit : スクリーンショットを各デバイス画像にはめる
  • pem : プッシュ通知プロファイルの生成と更新
  • sigh : プロビジョニングプロファイルのダウンロード、更新、生成等
  • produce : iTunes Connectで新しいiOSアプリを作成
  • cert : code signing certificates の作成と管理
  • codes : プロモコードの作成 *deprecated
  • spaceship : iTunes ConnectやApple Dev Centerにアクセス
  • pilot : TestFlightテスターの管理
  • boarding : TestFlightテスターの招待
  • gym : アプリのビルド
  • match : Gitで証明書とプロファイルをチーム管理

他にもcocoapodsslackなど様々なアクションが用意されている。

設定例

Fastfileにレーンの定義を記述することで、下記のようにコマンドラインで実行が可能となる。

$ fastlane appstore
lane :appstore do
  increment_build_number
  cocoapods
  xctool
  snapshot
  sigh
  deliver
  frameit
  sh "./customScript.sh"

  slack
end

レーンの実行前後の処理や、エラーハンドリングも可能。

before_all do |lane|
  increment_build_number
  cocoapods
end
after_all do |lane|
  clean_build_artifacts
  commit_version_bump
  add_git_tag
end
error do |lane, exception|
  reset_git_repo
  slack({
    message: "An error occured"
  })
end

実用例

ビルドした際に自動でプロビジョニングファイルを生成し、
FabricのCrashlyticsでテスト配布を行う設定。

fastlane_version "1.97.2"

default_platform :ios

platform :ios do
  before_all do
    # Crashlyticsの設定
    ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
    ENV["CRASHLYTICS_API_TOKEN"] = "..."
    ENV["CRASHLYTICS_BUILD_SECRET"] = "..."

    # pod install
    cocoapods
  end

  after_all do |lane|
    slack(
       message: "Successfully deployed new App Update."
     )
  end

  error do |lane, exception|
    slack(
      message: exception.message,
      success: false
     )
  end


  desc "Crashlyticsでグループに配布"
  lane :crashlytics do

    # CI環境で実行の場合のみimport_certificatesを実行
    import_certificates if Helper.is_ci?

    sigh(
      app_identifier: "...",
      development: true
    )

    gym(
      workspace: "<...>.xcworkspace",
      scheme: "...",
      configuration: 'Beta',
      clean: true
    )

    crashlytics(
      crashlytics_path: "./Pods/Crashlytics/iOS/Crashlytics.framework",
      notes: "Fastlaneによる配布",
      api_token: ENV["CRASHLYTICS_API_TOKEN"],
      build_secret: ENV["CRASHLYTICS_BUILD_SECRET"],
      ipa_path: "<APP>.ipa",
      groups: "developer"
    )
  end

  private_lane :import_certificates do

    ENV["KEYCHAIN_NAME"] = "ios-build.keychain"
    ENV["KEYCHAIN_PASSWORD"] = "..."
    ENV["CERT_PASSWORD"] = ENV["FASTLANE_PASSWORD"]

    # キーチェーンを作成する
    create_keychain(
      name: ENV["KEYCHAIN_NAME"],
      password: ENV["KEYCHAIN_PASSWORD"],
      default_keychain: true,
      unlock: true,
      timeout: 3600,
      lock_when_sleeps: true
    )

    # 証明書をimport。リポジトリのパスを指定
    import_certificate certificate_path: "./fastlane/certificate/AppleWWDRCA.cer"
    import_certificate certificate_path: "./fastlane/certificate/dist.p12", certificate_password: ENV["CERT_PASSWORD"]
  end
end

...は各自設定)

参考

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8