解決しようとしている問題
carthage update --platform iOS
を実行した時、下記のように出力されてライブラリのビルドに失敗することがある。
これの解決方法を記す。
➜ MultipeerTrial git:(master) ✗ carthage update --platform iOS
*** Fetching RxMultipeer
.
.
.
** BUILD FAILED **
The following build commands failed:
CompileSwift normal arm64 /Users/colorbox222/develop/ios/trial/MultipeerTrial/Carthage/Checkouts/RxMultipeer/RxMultipeerTests/IntegrationSpec.swift
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)
/Users/colorbox222/develop/ios/trial/MultipeerTrial/Carthage/Checkouts/RxMultipeer/RxMultipeerTests/IntegrationSpec.swift:2:8: error: no such module 'Quick'
A shell task (/usr/bin/xcrun xcodebuild -project /Users/colorbox222/develop/ios/trial/MultipeerTrial/Carthage/Checkouts/RxMultipeer/RxMultipeer.xcodeproj -scheme RxMultipeer -configuration Release -sdk iphoneos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build) failed with exit code 65:
** BUILD FAILED **
The following build commands failed:
CompileSwift normal arm64 /Users/colorbox222/develop/ios/trial/MultipeerTrial/Carthage/Checkouts/RxMultipeer/RxMultipeerTests/IntegrationSpec.swift
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)
Carthageで導入しようとしているライブラリのビルドに失敗している状態である。
これを正常にビルドできるようにする方法について記す。
おおまかな手順
ビルドに失敗しているプロジェクトをGithub上でforkする。
forkしたプロジェクトをローカルにcloneし手元で修正、pushする。
自前のプロジェクト用のリリースを作成。
その後、Cartfileの参照先とバージョンを自前のリポジトリ用に変更し、carthage update --platform iOS
を実行。
解説
carthage でのライブラリのビルド時はCartfileに記述したGithubのリポジトリを参照している。
これにビルドが不可能となるようなバグや設定ミスが含まれていると、ライブラリのビルド作業自体が途中で止まってしまう。
また、自分のものでなければGithub上のリポジトリ修正をすぐに反映できない。
そこで、forkを行うことで問題のあるリポジトリの修正を手元ですぐにできるようにする。
Cartfileから自分のリポジトリを参照させても、carthageによるビルドは問題なく動作する。
実例
下記ライブラリを使って実例を示す。
https://github.com/RxSwiftCommunity/RxMultipeer
上記ライブラリをしようとしてCarthageでのビルドを行おうとすると、下記エラーが発生する。
➜ MultipeerTrial git:(master) ✗ carthage update --platform iOS
*** Fetching RxMultipeer
*** Fetching RxSwift
*** Checking out RxSwift at "2.6.0"
*** Checking out RxMultipeer at "1.1.3"
*** xcodebuild output can be found in /var/folders/46/n6mt57_90gsgjwp21ywdg2t40000gn/T/carthage-xcodebuild.t9h2Lx.log
*** Building scheme "RxSwift-iOS" in Rx.xcworkspace
*** Building scheme "RxCocoa-iOS" in Rx.xcworkspace
*** Building scheme "RxTests-iOS" in Rx.xcworkspace
*** Building scheme "RxBlocking-iOS" in Rx.xcworkspace
*** Building scheme "RxMultipeer" in RxMultipeer.xcodeproj
** BUILD FAILED **
The following build commands failed:
CompileSwift normal arm64 /Users/colorbox222/develop/ios/trial/MultipeerTrial/Carthage/Checkouts/RxMultipeer/RxMultipeerTests/IntegrationSpec.swift
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)
/Users/colorbox222/develop/ios/trial/MultipeerTrial/Carthage/Checkouts/RxMultipeer/RxMultipeerTests/IntegrationSpec.swift:2:8: error: no such module 'Quick'
A shell task (/usr/bin/xcrun xcodebuild -project /Users/colorbox222/develop/ios/trial/MultipeerTrial/Carthage/Checkouts/RxMultipeer/RxMultipeer.xcodeproj -scheme RxMultipeer -configuration Release -sdk iphoneos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build) failed with exit code 65:
** BUILD FAILED **
The following build commands failed:
CompileSwift normal arm64 /Users/colorbox222/develop/ios/trial/MultipeerTrial/Carthage/Checkouts/RxMultipeer/RxMultipeerTests/IntegrationSpec.swift
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)
エラー内容を見ると、RxMultipeerTests、つまりテスト用のターゲットにおいて、ビルドが失敗していることを示している。
テスト用であれば、実際に使う分には問題ため、テスト用のターゲットを削除することでビルドが通りそうだということが推測できる。
forkした後にテスト用のターゲットを削除したリポジトリがこちら。
https://github.com/colorbox/RxMultipeer
こちらを使用してビルドを行うと、正常にビルドが完了する。
➜ MultipeerTrial git:(master) ✗ carthage update --platform iOS
*** Fetching RxMultipeer
*** Fetching RxSwift
*** Checking out RxSwift at "2.6.0"
*** Checking out RxMultipeer at "1.2.0"
*** xcodebuild output can be found in /var/folders/46/n6mt57_90gsgjwp21ywdg2t40000gn/T/carthage-xcodebuild.8qiyTA.log
*** Building scheme "RxBlocking-iOS" in Rx.xcworkspace
*** Building scheme "RxTests-iOS" in Rx.xcworkspace
*** Building scheme "RxCocoa-iOS" in Rx.xcworkspace
*** Building scheme "RxSwift-iOS" in Rx.xcworkspace
*** Building scheme "RxMultipeer" in RxMultipeer.xcodeproj