話題の記事

[iOS] iOS アプリのリリースプロセスを自動化してくれる fastlane の初期セットアップ方法

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

はじめに

先日、iOS のリリースプロセスを大きく自動化してくれる fastlane についてご紹介しました。

[iOS] iOS アプリのリリースプロセスを自動化してくれる fastlane の 勉強会 に参加してきました

今回は、fastlane をインストールし、プロジェクトフォルダに fastlane の各種設定ファイル等を組み込む方法をお伝えします。

インストール

KrauseFx/fastlaneを確認しながらインストールを進めました。

sudo gem install fastlane --verbose

上記のように入力します。

To install Command Line Tools, try running `xcode-select --install` on
terminal and follow the instructions.  If it fails, open Xcode.app,
select from the menu "Xcode" - "Open Developer Tool" - "More Developer
Tools" to open the developer site, download the installer for your OS
version and run it.

すると、途中でエラーが表示されました。 アドバイスとして、Command Line Tools を正しくインストールするようメッセージが表示された後、インストール方法が表示されました。

xcode-select --install

上記コマンドを実行後、表示されたダイアログに従いインストールしました。

sudo gem install fastlane --verbose

改めて上記を実行し、数分かけて、多数の gem がインストールされていきました。

プロジェクトフォルダに fastlane を組み込む

fastlane init

fastlane を使いたいプロジェクトフォルダ内に移動し、上記コマンドを入力すると、初期設定を進めていくことができます。 対話形式で設定を進めていくことができ大変便利です。ここでは、一例を書いていきます。

This setup will help you get up and running in no time.
First, it will move the config files from `deliver` and `snapshot`
into the subfolder `fastlane`.
fastlane will check what tools you're already using and set up
the tool automatically for you. Have fun!

はじめの断り書きが書いてあります。Have fun!

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

はじめますか? と聞かれていますので、"y"(はい)と入力します。

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

バージョンコントロールを使って管理しているかを尋ねられます。 Git で管理しているので、"y"(はい)と入力しています。 ここで "n"(いいえ)と入力すると、そこで終了します。

Created new folder './fastlane'.

ここで、fastlane フォルダが作成されます。もしこれまでに、fastlane ファミリーのコマンドツールである、deliversnapshot を使っていた場合、それらのフォルダの位置が、fastlane フォルダの中に移動されるようです。

To not re-enter your username and app identifier every time you run one of the fastlane tools or fastlane, these will be stored from now on.
App Identifier (com.krausefx.app): com.xxxxxxxxxxx.fastlane-exp
Your Apple ID (fastlane@krausefx.com): xxx@xxxxxxxxxxx.com

fastlaneiTunes Connect にログインして作業できるよう、以下の情報を入力します。 * アプリの Bundle Identifier * アプリをアップロードするのに使用する Apple ID

Created new file './fastlane/Appfile'. Edit it to manage your preferred app metadata information.

情報をおさめた Appfile が作成されます。

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)
y

スクリーンショットやアプリのメタデータ等を App StoreTestFlight にアップするための deliver を使うか聞かれます。"y"(はい)と入力しました。

Loading up 'deliver', this might take a few seconds
Phantomjs does not appear to be installed in /Users/qair/.phantomjs/1.9.8/darwin/bin/phantomjs, installing!

(略)

Successfully installed phantomjs. Yay!
Removed temporarily downloaded files.

機能の使用には、PhantomJS が必要になります。インストールされていない場合は、ここでインストールされます。

Do you want Deliver to automatically create the Deliverfile for you based
on your current app? The app has to be in the App Store to use this
feature. (y/n)
y

すでに App Store にあるアプリを扱う場合は、"y"(はい)を入力します。今回は、あらかじめ App Store でアプリを登録してあるので、"y"(はい)を入力しました。

First, you need to login with your iTunesConnect credentials.
This is necessary to fetch the latest metadata from your app and use it to create a Deliverfile for you.
If you have previously entered your credentials already, you will not be asked again.
No username or password given. You can set environment variables:
DELIVER_USER, DELIVER_PASSWORD
-------------------------------------------------------------------------------------
The login information you enter will be stored in your Mac OS Keychain
More information about that on GitHub: https://github.com/fastlane/CredentialsManager
-------------------------------------------------------------------------------------
Password (for xxx@xxxxxx.com): ***************

ここでは、iTunes Connect のログイン用パスワードを入力します。 一度入力すれば、Mac OS のキーチェーンに保存され、2回目以降は入力の必要がなくなります。

(略)

Successfully downloaded existing metadata for language en-US
Successfully created new configuration files at './fastlane/metadata'
Downloading all previously used app screenshots.
Logging into iTunesConnect
Successfully created new Deliverfile at './fastlane/Deliverfile'

既存のメタデータやスクリーンショットを iTunes Connect から取得してきてくれます。 情報を元に、アプリのタイトルや説明文等のデータが収まっている metadata フォルダが作成されます。 その後、アプリの IdentifierApple ID などの情報などがあらかじめ設定された、deliver の設定ファイルである Deliverfile が作成されます。

Do you want to setup 'snapshot', which will help you to automatically take
screenshots of your iOS app in all languages/devices? (y/n)
y

スナップショットを自動で作成するかを尋ねられます。"y"(はい)と答えています。

Loading up 'snapshot', this might take a few seconds
#############################################################
# xctool is recommended to build the apps
# Install it using 'brew install xctool'
# Falling back to xcode build instead
#############################################################
Successfully created SnapshotHelper.js './fastlane/SnapshotHelper.js'
Successfully created new UI Automation JS file at './fastlane/snapshot.js'
Successfully created new UI Automation JS file for iPad at './fastlane/snapshot-iPad.js'
Successfull

自動でスナップショットを撮影する機能を実現するためのファイルが生成されます。

Do you want to use 'sigh', which will maintain and download the provisioning
profile for your app? (y/n)
y

プロビジョニングの管理をしてくれる sigh を使用するか尋ねられます。"y"(はい)と答えています。

 Optional: The scheme name of your app. If you don't need one, just click
enter:

scheme 名を尋ねられています。指定の必要がない場合は、そのままエンターキーを入力します。

'deliver' enabled.
'snapshot' enabled.
'xctool' not enabled.
'cocoapods' not enabled.
'sigh' enabled.
Created new file './fastlane/Fastfile'. Edit it to manage your own deployment lanes.
fastlane will send the number of errors for each action to
https://github.com/fastlane/enhancer to detect integration issues
No sensitive/private information will be uploaded
You can disable this by adding `opt_out_usage` to your Fastfile
Successfully finished setting up fastlane

最後に、今回どの機能が有効になったのか等の情報が表示されます。

.
├── LICENSE
├── README.md
├── fastlane
│   ├── Appfile
│   ├── Deliverfile
│   ├── Fastfile
│   ├── Snapfile
│   ├── SnapshotHelper.js
│   ├── actions
│   ├── metadata
│   │   └── en-US
│   │       ├── description.txt
│   │       ├── keywords.txt
│   │       ├── privacy_url.txt
│   │       ├── software_url.txt
│   │       ├── support_url.txt
│   │       ├── title.txt
│   │       └── version_whats_new.txt
│   ├── screenshots
│   │   └── README.txt
│   ├── snapshot-iPad.js
│   └── snapshot.js
├── fastlane-exp
│   ├── AppDelegate.h
│   ├── AppDelegate.m
│   ├── Base.lproj
│   │   ├── LaunchScreen.xib
│   │   └── Main.storyboard
│   ├── Images.xcassets
│   │   └── AppIcon.appiconset
│   │       └── Contents.json
│   ├── Info.plist
│   ├── ViewController.h
│   ├── ViewController.m
│   └── main.m
├── fastlane-exp.xcodeproj
│   ├── project.pbxproj
│   ├── project.xcworkspace
│   │   ├── contents.xcworkspacedata
│   │   ├── xcshareddata
│   │   │   └── fastlane-exp.xccheckout
│   │   └── xcuserdata
│   │       └── qair.xcuserdatad
│   │           └── UserInterfaceState.xcuserstate
│   └── xcuserdata
│       └── qair.xcuserdatad
│           └── xcschemes
│               ├── fastlane-exp.xcscheme
│               └── xcschememanagement.plist
└── fastlane-expTests
    ├── Info.plist
    └── fastlane_expTests.m

今回の設定により、プロジェクトフォルダの構造はこのようになりました。

まとめ

対話形式で設定が進んでいくのはとてもベンリだと感じました。 基本的な設定は完了しましたが、さらに別の処理を入れたいときなどは、別途記述することで対応出来ます。 進化を続ける fastlane にこれからも期待です!