LCL Engineers' Blog

夜行バス比較なび(高速バス比較)・格安移動・バスとりっぷを運営する LCLの開発者ブログ

Bitriseで動作するFastlane/Gymでビルドが失敗する問題の解決方法

Xcode9 / Swift4の対応後、とあるブランチを配布しようとした際に PodsでインストールしたライブラリでProvisioning Profileが参照できずビルドが失敗する現象が発生しました。

以下はBitrise上のログです。(Provisioning Profile等の情報は伏せてあります)

[02:35:57]: Detected provisioning profile mapping: {:"XXX"=>"XXX"}

+--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------+
| Summary for gym 2.62.1 |
+--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------+
| clean | true |
| xcargs | DEVELOPMENT_TEAM="XXX" PROVISIONING_PROFILE_SPECIFIER="XXX" CODE_SIGN_IDENTITY="iPhone Distribution" |
| scheme | XXX |
| export_method | ad-hoc |
| export_options.provisioningProfiles.XXX | XXX |
| workspace | ./XXX.xcworkspace |
| destination | generic/platform=iOS |
| output_name | XXX |
| build_path | /Users/vagrant/Library/Developer/Xcode/Archives/2017-10-30 |
| output_directory | . |
| silent | false |
| skip_package_ipa | false |
| buildlog_path | /var/folders/90/5stft2v13fb_m_2dsfafd0gn/T/fastlane_logs222222/gym |
| skip_profile_detection | false |
| xcode_path | /Applications/Xcode-beta.app |
+--------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------+

[02:35:57]: $ set -o pipefail && xcodebuild -workspace ./XXX.xcworkspace -scheme XXX -destination 'generic/platform=iOS' -archivePath /Users/vagrant/Library/Developer/Xcode/Archives/2017-10-30/XXX\ 2017-10-30\ 02.35.57.xcarchive DEVELOPMENT_TEAM="XXX" PROVISIONING_PROFILE_SPECIFIER="XXX" CODE_SIGN_IDENTITY="iPhone Distribution" clean archive | tee /var/folders/90/5stft2v13fb_m_gv3c8x9asdfagn/T/fastlane_logs23ddd6627/gym/XXX.log | xcpretty

[02:36:02]: ▸ ❌ error: AWSCore does not support provisioning profiles. AWSCore does not support provisioning profiles, but provisioning profile XXX has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor. (in target 'AWSCore')

[02:36:02]: ▸ ❌ error: AWSSNS does not support provisioning profiles. AWSSNS does not support provisioning profiles, but provisioning profile XXX has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor. (in target 'AWSSNS')

...

[02:36:02]: ▸ ❌ error: Pods-XXX does not support provisioning profiles. Pods-XXX does not support provisioning profiles, but provisioning profile XXX has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor. (in target 'Pods-XXX')

[02:36:02]: ▸ Target Pods-XXX product Pods_XXX cannot link framework Foundation.framework

[02:36:02]: ▸ Target Pods-XXX product Pods_XXX cannot link framework Foundation.framework

[02:36:02]: ▸ unexpected duplicate creator 'PhaseScriptExecution [CP]\ Copy\ Pods\ Resources /Users/vagrant/Library/Developer/Xcode/DerivedData/XXX-dwpikqfheukvzieglddgbhcojmrj/Build/Intermediates.noindex/ArchiveIntermediates/XXX-dev/IntermediateBuildFilesPath/XXX.build/Test-iphoneos/XXX.build/Script-C604611C209DA5CF0468AAE9.sh' for node '/Users/vagrant/Library/Developer/Xcode/DerivedData/XXX-dwpikqfheukvzieglddgbhcojmrj/Build/Intermediates.noindex/ArchiveIntermediates/XXX-dev/InstallationBuildProductsLocation/Applications/XXX.app' with prior creator 'MkDir /Users/vagrant/Library/Developer/Xcode/DerivedData/XXX-dwpikqfheukvzieglddgbhcojmrj/Build/Intermediates.noindex/ArchiveIntermediates/XXX-dev/InstallationBuildProductsLocation/Applications/XXX.app' (in target 'XXX')

[02:36:02]: ▸ ignoring duplicated output file: '/Users/vagrant/Library/Developer/Xcode/DerivedData/XXX-dwpikqfheukvzieglddgbhcojmrj/Build/Intermediates.noindex/ArchiveIntermediates/XXX-dev/InstallationBuildProductsLocation/Applications/XXX.app' (in target 'XXX')

[02:36:02]: ▸ ** ARCHIVE FAILED **

❌ error: AWSCore does not support provisioning profiles. AWSCore does not support provisioning profiles, but provisioning profile XXX has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor. (in target 'AWSCore')

❌ error: AWSSNS does not support provisioning profiles. AWSSNS does not support provisioning profiles, but provisioning profile XXX has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor. (in target 'AWSSNS')

❌ error: DZNWebViewController does not support provisioning profiles. DZNWebViewController does not support provisioning profiles, but provisioning profile XXX has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor. (in target 'DZNWebViewController')

❌ error: OALayoutAnchor does not support provisioning profiles. OALayoutAnchor does not support provisioning profiles, but provisioning profile XXX has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor. (in target 'OALayoutAnchor')

❌ error: SimulatorRemoteNotifications does not support provisioning profiles. SimulatorRemoteNotifications does not support provisioning profiles, but provisioning profile XXX has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor. (in target 'SimulatorRemoteNotifications')

❌ error: TTRangeSlider does not support provisioning profiles. TTRangeSlider does not support provisioning profiles, but provisioning profile XXX has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor. (in target 'TTRangeSlider')

❌ error: Pods-XXX does not support provisioning profiles. Pods-XXX does not support provisioning profiles, but provisioning profile XXX has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor. (in target 'Pods-XXX')

Target Pods-XXX product Pods_XXX cannot link framework Foundation.framework

Target Pods-XXX product Pods_XXX cannot link framework Foundation.framework

unexpected duplicate creator 'PhaseScriptExecution [CP]\ Copy\ Pods\ Resources /Users/vagrant/Library/Developer/Xcode/DerivedData/XXX-dwpikqfhefdsfgbhcojmrj/Build/Intermediates.noindex/ArchiveIntermediates/XXX-dev/IntermediateBuildFilesPath/XXX.build/Test-iphoneos/XXX.build/Script-C604611C20EEE0468AAE9.sh' for node '/Users/vagrant/Library/Developer/Xcode/DerivedData/XXX-dwpikadfeglddgbhcojmrj/Build/Intermediates.noindex/ArchiveIntermediates/XXX-dev/InstallationBuildProductsLocation/Applications/XXX.app' with prior creator 'MkDir /Users/vagrant/Library/Developer/Xcode/DerivedData/XXX-dwpikasdfavzieglddgbhcojmrj/Build/Intermediates.noindex/ArchiveIntermediates/XXX-dev/InstallationBuildProductsLocation/Applications/XXX.app' (in target 'XXX')

ignoring duplicated output file: '/Users/vagrant/Library/Developer/Xcode/DerivedData/XXX-dwpikqfheukvzieglddgbhcojmrj/Build/Intermediates.noindex/ArchiveIntermediates/XXX-dev/InstallationBuildProductsLocation/Applications/XXX.app' (in target 'XXX')

** ARCHIVE FAILED **

[02:36:02]: Exit status: 65

+---------------+------------------------------+
| Build environment |
+---------------+------------------------------+
| xcode_path | /Applications/Xcode-beta.app |
| gym_version | 2.62.1 |
| export_method | ad-hoc |
| sdk | iPhoneOS11.1.sdk |
+---------------+------------------------------+

[02:36:02]: ▸ Build system information

[02:36:02]: ▸ warning: unexpected duplicate creator 'PhaseScriptExecution [CP]\ Copy\ Pods\ Resources /Users/vagrant/Library/Developer/Xcode/DerivedData/XXX-dwpikqasdfvzieglddgbhcojmrj/Build/Intermediates.noindex/ArchiveIntermediates/XXX-dev/IntermediateBuildFilesPath/XXX.build/Test-iphoneos/XXX.build/Script-C604611C2EEEE0468AAE9.sh' for node '/Users/vagrant/Library/Developer/Xcode/DerivedData/XXX-dwpikqfheasdfvzieglddgbhcojmrj/Build/Intermediates.noindex/ArchiveIntermediates/XXX-dev/InstallationBuildProductsLocation/Applications/XXX.app' with prior creator 'MkDir /Users/vagrant/Library/Developer/Xcode/DerivedData/XXX-dwpikqfheudsafddgbhcojmrj/Build/Intermediates.noindex/ArchiveIntermediates/XXX-dev/InstallationBuildProductsLocation/Applications/XXX.app' (in target 'XXX')

[02:36:02]: ▸ Build system information

[02:36:02]: ▸ warning: ignoring duplicated output file: '/Users/vagrant/Library/Developer/Xcode/DerivedData/XXX-dwpikqfhadfdaieglddgbhcojmrj/Build/Intermediates.noindex/ArchiveIntermediates/XXX-dev/InstallationBuildProductsLocation/Applications/XXX.app' (in target 'XXX')

[02:36:02]:

[02:36:02]: ⬆️ Check out the few lines of raw `xcodebuild` output above for potential hints on how to solve this error

解決方法

Fastfileのgymメソッドに以下のオプションをを追加します。 PROVISIONING_PROFILE_SPECIFIERで使用するProvisioning Profileを指定します。

    gym(
        clean: true,
        xcargs: xcodebuild_args,
        scheme: options[:scheme],
        verbose: true,
        + export_options: {
        + provisioningProfiles: {
        +  BUNDLE_ID => PROVISIONING_PROFILE_NAME
        + }
        + },
        + xcargs: "PROVISIONING_PROFILE_SPECIFIER='#{PROVISIONING_PROFILE_NAME}'"
    )

又、CODE_SIGN_IDENTITYがProvisioning Profileに紐付いていないものが設定されているとエラーとなります。

         buildSettings = {
                ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
                CODE_SIGN_ENTITLEMENTS = "XXX/XXX.entitlements";
                CODE_SIGN_IDENTITY = "iPhone Distribution";
                - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: 紐付いていない個人証明書 (XXX)";
                + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
                DEVELOPMENT_TEAM = XXX;
                FRAMEWORK_SEARCH_PATHS = (
                    "$(inherited)",

原因

gymのexport_optionsについては、xcode9からmatchを使っていない場合に明記する必要があるとのことです。

https://docs.fastlane.tools/codesigning/xcode-project/#xcode-9-and-up

またProvisining Profileを設定しないとxcode側で自動でAutomatically manage signingになる(?)とのことで PROVISIONING_PROFILE_SPECIFIERでの設定が必要となります。

CODE_SIGN_IDENTITY については、恐らくどこかのタイミングでAutomatically manage signingを設定してしまい 対象のビルド環境のCode Signing Identityの設定が証明書とProvisioning Profileの紐付かないものになっていました。

開発環境の証明書にはmatchを使っているのですが、リリースの証明書周りは以前から作られている証明書を使っているため 参照する証明書の設定がズレていたのが原因です。

ハマったポイント

  • Bitrise上のログ(特にProvisioning Profile等の文字列)は成功時のものと同じ
  • Xcode9が原因かと思われたが同環境のdevelopブランチは成功した
    • 動作するdevelopブランチのxcodeprojをチェックアウトしてきても発生した
  • 上のことからCacheが影響していた?(Podsフォルダが残っていて成功していた可能性があったのでPodsフォルダを都度削除するようにした)
  • Xcode 9で同様のIssueがたくさん立てられていたが、この問題は実はXcode9ではなくXcode8からある現象だった
  • Apple側がAutomatically manage signingを推奨している(設定しないと自動で"自動"に切り替わる)
  • Bitrise上でのみでしか実行を試せなかったので手間と時間が余計にかかった

終わりに

言語やXcodeの変わり目ではこういった変更と合併した設定ミスでハマりやすいですね。 ローカルで動作する環境を用意しなかったのも余計に時間がかかった原因でした。 自動化をすると疎かになりがちですが、個々の設定内容も理解しなければいけないと思います。