3
0

More than 1 year has passed since last update.

[iOS] carthage で XCFramework に対応する

Posted at

現象

xcode 13 も正式リリースされ、carthage で入れるライブラリをビルドしたところ、以下のエラーが発生しました。

XXXX have the same architectures(arm64) and can't be in the same fat output file.

詳細

xcode 12 以降では M1CPU(ARM64系)のMac上のエミュレーターに対応したため、iOS 用とエミュレータ用で2つの arm64 が存在することになり、carthage のビルドに失敗することがあります。
 
以前は Carthage 本家に、以下のようにスクリプトで対応する方法がありました。
https://github.com/Carthage/Carthage/blob/master/Documentation/Xcode12Workaround.md
しかし今回、xcode 13 ではこの方法ではビルド出来ず、上記のエラーが発生しました。

解決法

対応としては、framework ファイルではなく、XCFramework をビルドすることによって解決できました。

carthage を V0.37.0 以降に更新することで XCFramework に対応できるようになり、上記のようなワークアラウンドで回避せずともビルドが通り、かつ簡単に iOS, エミュレータの両方に対応できるようになったようです。
 参考)https://techlife.cookpad.com/entry/2021/03/10/110000
 

XCFramework 形式で Framework をビルドすることで対応する。

1.project/Cathage 以下のファイルを一旦削除
2.XCFramework としてビルド("--use-xcframeworks")

 carthage update --platform iOS --use-xcframeworks

・framework バイナリがダウンロードされる場合は、"--no-use-binaries" オプションを付け、ローカルでxcframework をビルドする。
3.project/Cathage/Build/*.xcframework フォルダを Project > General > Frameworks, Libraries, and Embedded Content にドロップ
  ・従来の *.framework は削除しておく
  ・Build Phase の Run Script に追加していた carthage copy-frameworks は不要になるので削除
4.Clean Build Folder 後、Build を実行する

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