LoginSignup
0
2

More than 1 year has passed since last update.

スマホアプリのコマンドビルドまとめ(iOS編)

Last updated at Posted at 2022-06-03

前回、『XCTestCaseで作ったテストをxcodebuildで実行する方法』についてまとめましたが、引き続きxcodebuildでシミュレータビルドと.ipaファイルのビルドをやったのでその試験のまとめです。

概要

目的は以下の2点です。

  • iOSシミュレータにアプリを転送して実行させる
  • .ipaファイルを作る

準備

以下の準備を済ませておくこと。

シミュレータ

以下の各記事を参考に実機でのビルドよりも先にシミュレータビルドを行う。

$ xcrun simctlでは、シミュレータの画面が表示されないため状況が分からないことから別の方法で対応することに。
まずは、シミュレータに転送できる.appファイルをビルドするところまで作業する。

$ cd ios_app

# .appファイルをビルド
xcodebuild \
  -workspace AppName.xcworkspace \
  -scheme AppName \
  -destination OS=13.2,name="iPhone 11" \
  -derivedDataPath ./build  \
  clean build

# `-derivedDataPath`がない時のビルド先
# /Users/gremito/Library/Developer/Xcode/DerivedData/AppName-xxxxxxxxxxxxxxxxxxxxxxx/Build/Products/Debug-iphonesimulator/AppName.app

上記の場合、ios_app/build/Build/Products/Debug-iphonesimulator/AppName.app

実機端末

.ipaファイルをビルドします。『ipaファイルのエクスポートとdeploygateへのアップロードの自動化しました』という記事を参考にさせていただきました🙏

$ cd ios_app

# アーカイブをビルド
$ xcodebuild   \
  -workspace AppName.xcworkspace \
  -scheme AppName \
  -configuration Release archive \
  -archivePath ./build/AppName.xcarchive

# アプリをビルド
$ xcodebuild  \
  -exportArchive  \
  -archivePath  ./build/AppName.xcarchive  \
  -exportPath ./build  \
  -exportOptionsPlist ./build/AppName.xcarchive/Info.plist

実機へのアプリ転送とアプリの実行は次のどれかのツールを使って試すことにしてまだ未対応。

申請用ビルド

次の記事が参考になりました。

# アーカイブ時のみ
$ xcodebuild  \
  -workspace AppName.xcworkspace \
  -scheme AppName \
  -configuration Release archive \
  -archivePath ./build/AppName.xcarchive \
  CODE_SIGN_IDENTITY="${SIGN}" \
  PROVISIONING_PROFILE_SPECIFIER=${PROVISIONING}

fbsimctlidb

Facebookが作ったiOSシミュレーターとデバイスを自動化するためのCLIツールとのこと。

idbを使うとシミュレータの起動→アプリ転送→アプリ起動→アプリ終了のコマンドを動作確認しました。

# シミュレータ起動
$ idb boot --udid XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX
# シミュレータ連携
$ idb connect XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX
# アプリ転送
$ idb install ~/ios_app/build/AppName.xcarchive/Products/Applications/AppName.app
# アプリ起動
$ idb launch net.gremito.ios.appname
# アプリ終了
$ idb terminate net.gremito.ios.appname
# アプリ削除
$ idb uninstall net.gremito.ios.appname

Appium

appiumは、デスクトップ版とCLI版があり、CI環境を作る場合は、appium/appiumにあるgetting-started.mdを参考にCLI版を入れる方が良い。

appiumの最初の難関は、$appium doctorで❌が表示している内容を対応するところでしょう。
と言ってもすんなり終わる場合もあるのでappiumを使う前に問題は把握して対処しておく。

Airtest

サクッと試したかったが、そもそもPythonの管理でガッツリハマる。

次にopencv-contrib-pythonのインストール時に指定した古いバージョンが取れなかった。
おそらくopencv-pythonも同様だと思い、少し調査して対応していたもののサクッとできなかったため中断した。

$ python3 -m pip install -U airtest
Collecting airtest
  Using cached 

# 省略

Collecting opencv-contrib-python<=3.4.2.17 (from airtest)
  ERROR: Could not find a version that satisfies the requirement opencv-contrib-python<=3.4.2.17 (from airtest) (from versions: 3.4.8.29, 4.1.2.30)
ERROR: No matching distribution found for opencv-contrib-python<=3.4.2.17 (from airtest)
WARNING: You are using pip version 19.2.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

おまけ

Debug-iphonesimulatorについて

シミュレータビルドの際、ios_app/build/Build/Products/Debug-iphonesimulator/AppName.appに成果物ができています。
コマンドラインでもiPhone 11と指定しているので気づきにくいですが、iPadの場合はDebug-iphonesimulatorではなく、Debug-ipadsimulatorと作られパスが変わってしまうのか、という疑問について。

$ xcodebuild -showsdks
iOS SDKs:
	iOS 13.2                      	-sdk iphoneos13.2

iOS Simulator SDKs:
	Simulator - iOS 13.2          	-sdk iphonesimulator13.2

macOS SDKs:
	DriverKit 19.0                	-sdk driverkit.macosx19.0
	macOS 10.15                   	-sdk macosx10.15

tvOS SDKs:
	tvOS 13.2                     	-sdk appletvos13.2

tvOS Simulator SDKs:
	Simulator - tvOS 13.2         	-sdk appletvsimulator13.2

watchOS SDKs:
	watchOS 6.1                   	-sdk watchos6.1

watchOS Simulator SDKs:
	Simulator - watchOS 6.1       	-sdk watchsimulator6.1

上記のようにiOS Simulator SDKsは一律iphonesimulator13.2と括られています。
試しに-destination OS=13.2,name="iPad (7th generation)"とオプションの値を変えてビルドしてみたところパスは変わらずでDebug-iphonesimulatorでした。

 

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