【Fastlane】The following build commands failed CopySwiftLibs エラーが出た時

ローカル環境では特に問題ないけど、ビルドマシンのmac-miniにsshでログインしてgymを実行したり mac-miniのjenkinsからgymを実行すると 以下エラー等が出て困った。

  • The following build commands failed:CopySwiftLibs
  • The following build commands failed:CodeSign

ビルドする端末のキーチェーンアクセスを開いて該当する証明書をログインではなく、システムに入れればいいみたい。

余談ですが、上記エラーと一緒に以下のエラーが出ていました。

[16:37:53]: [31mExit status: 65[0m
[16:37:53]: [33m📋  For a more detailed error log, check the full log at:[0m
[16:37:53]: [33m📋  /Users/yamanaka/Library/Logs/gym/MEME-Run-iOS-MEME-Run-iOS.log[0m
[16:37:53]: [31mFound multiple versions of Xcode in '/Applications/'[0m
[16:37:53]: [31mMake sure you selected the right version for your project[0m
[16:37:53]: [31mThis build process was executed using '/Applications/Xcode.app'[0m
[16:37:53]: [33mIf you want to update your Xcode path, either[0m
[16:37:53]: 
[16:37:53]: - Specify the Xcode version in your Fastfile
[16:37:53]: ▸ [35mxcversion(version: "8.1") # Selects Xcode 8.1.0[0m
[16:37:53]: 
[16:37:53]: - Specify an absolute path to your Xcode installation in your Fastfile
[16:37:53]: ▸ [35mxcode_select "/Applications/Xcode8.app"[0m
[16:37:53]: 
[16:37:53]: - Manually update the path using
[16:37:53]: ▸ [35msudo xcode-select -s /Applications/Xcode.app[0m
[16:37:53]: 

僕の環境だと端末内に複数バージョンのXcodeが入っていたため、上記エラーの通りXcodeの指定がちゃんとできていないと思ってこの辺りを中心に調査して盛大に時間をロスしました。(ビルドに使用するXcodexcode_selectアクションで指定できます。 )

xcode_select "/Applications/Xcode.app"

上記のアクションを実行するようにしてFastlaneのビルドログを見ると以下のように使用するXcodeのpathが がちゃんと指定されているのにも関わらず Xcode指定してくれエラーが出続けました。

+----------------------+-------------------------------------------------------------+
|                               Summary for gym 2.36.0                               |
+----------------------+-------------------------------------------------------------+
| scheme               | Demo                                                        |
| export_method        | enterprise                                                  |
| configuration        | AdHoc                                                       |
| use_legacy_build_api | false                                                       |
| output_directory     | ./fastlane/ipa/enterprise/                                  |
| project              | ./Demo.xcodeproj                                            |
| destination          | generic/platform=iOS                                        |
| output_name          | Demo                                                        |
| build_path           | /Users/xxxxxxx/Library/Developer/Xcode/Archives/2017-06-07 |
| clean                | false                                                       |
| silent               | false                                                       |
| skip_package_ipa     | false                                                       |
| buildlog_path        | ~/Library/Logs/gym                                          |
| xcode_path           | /Applications/Xcode.app                                     |
+----------------------+-------------------------------------------------------------+

結局タイトルのエラーを解決したらこのXcode指定してくれエラーは消えて正常にビルドできるようになりました。

端末に複数バージョンXcodeが入っていて、かつThe following build commands failedが出ている場合に一緒に上記のエラーが出ているような気がします。

Exit status: 65- Found multiple versions of Xcode in '/Applications/' · Issue #8327 · fastlane/fastlane · GitHub

このissuesとかもXcodeの指定の問題じゃなくてThe following build commands failedエラーが出ていることが原因なんじゃないかなー。。