LoginSignup
1
0

コマンドラインでiOSアプリをビルドしシミュレータで起動する

Posted at

はじめに

本稿は、コマンドラインでiOSアプリをビルドし、シミュレータにインストールおよび起動する方法について書いています。

シェルスクリプトの作成

以下のbuild.shをプロジェクトのルートディレクトリに配置します。
build.shには chmod +x build.sh して実行権限を与えておきます。

build.sh
#!/bin/sh

SCHEME='Your Scheme'
SIM_NAME='iPhone 15' # シミュレータ名
DESTINATION="platform=iOS Simulator,name=$SIM_NAME"
CONFIG='Debug' # 'Debug' or 'Release'
DERIVED_DATA_PATH='./build'
APP_NAME='Your App Name'
APP_PATH="$DERIVED_DATA_PATH/Build/Products/$CONFIG-iphonesimulator/$APP_NAME.app"
BUNDLE_ID='your.bundle.id'

CLEAN=''; [ "$1" = "clean" ] && CLEAN='clean'

# アプリのビルド
xcodebuild -scheme $SCHEME -destination "$DESTINATION" -configuration $CONFIG -derivedDataPath $DERIVED_DATA_PATH $CLEAN build

# シミュレータの起動
xcrun simctl boot "$SIM_NAME"

# Xcodeのシミュレータアプリケーションを開く
open -a Simulator

# シミュレータにアプリをインストール
xcrun simctl install booted "$APP_PATH"

# シミュレータでアプリを起動
xcrun simctl launch booted "$BUNDLE_ID"

SCHEMEAPP_NAME などはプロジェクトに合わせて指定します。

SIM_NAME には、

xcrun simctl list devices

で出力される利用可能なシミュレータの名前を指定します。

build.shのそれぞれのコマンドの意味はコメントの通りです。

本稿執筆時点でのxcodebuildのバージョンは以下になります。

xcodebuild -version
Xcode 15.0
Build version 15A240d

シェルスクリプトの実行

./build.sh [clean]

clean はオプションです。 clean を付けるとクリーンビルドします。ただし、クリーンビルドはビルド時間が長くなる傾向にありますので、適宜付けたり付けなかったりしてください。

build.shを実行することで、iOSアプリをビルドし、指定したシミュレータで起動することができます。

1
0
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
1
0