12
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

サードパーティのライブラリ(framework)からxcframeworkを作成する

Last updated at Posted at 2021-03-03

環境

- Xcode: 12.3 (12C33)
- xcodegen: 2.18.0

前振り

:bow:「今度の案件でサードパーティfooのbarってライブラリ使うから導入おなしゃす」

:ok_hand:「おけまる」

bar-native-client-sdk-ios
├── FrameworksDevice
│   └── barSDK.framework
└── FrameworksSimulator
    └── barSDK.framework

:worried: 「なん…………だと………!!」


解決: universal framework編

:wink:「OK、universal frameworkになってないのね」

> lipo -info bar-native-client-sdk-ios/FrameworksDevice/barSDK.framework
Architectures in the fat file: bar-native-client-sdk-ios/FrameworksDevice/barSDK.framework is architecture: armv7 arm64

> lipo -info bar-native-client-sdk-ios/FrameworksSimulator/barSDK.framework
Architectures in the fat file: bar-native-client-sdk-ios/FrameworksSimulator/barSDK.framework is architecture: x86_64 i386 arm64

:relieved:「ならこうやってくっつけてっと」

lipo \
bar-native-client-sdk-ios/FrameworksDevice/barSDK.framework \
bar-native-client-sdk-ios/FrameworksSimulator/barSDK.framework \
-create -output build/universal-barSDK.framework

fatal error: /Applications/Xcode-12.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: bar-native-client-sdk-ios/FrameworksDevice/barSDK.framework and bar-native-client-sdk-ios/FrameworksSimulator/barSDK.framework have the same architectures (arm64) and can't be in the same fat output file

:confused:「しまった、arm64がダブってしまった...」

:grinning:「ならarm64を削除してからっと」

lipo \
-remove arm64 \
bar-native-client-sdk-ios/FrameworksSimulator/barSDK.framework \
-output build/barSDK_no_arm64.framework

lipo \
bar-native-client-sdk-ios/FrameworksDevice/barSDK.framework \
build/barSDK_no_arm64.framework \
-create -output build/universal-barSDK.framework

:thinking:「でもこれだとM1で動かないんだよね...」


真解決: xcframework編

:smile:「Xcode11からxcframeworkが使えるらしいな」

xcodebuild \
-create-xcframework \
-framework bar-native-client-sdk-ios/FrameworksDevice/barSDK.framework \
-framework bar-native-client-sdk-ios/FrameworksSimulator/barSDK.framework \
-output build/barSDK.xcframework

:laughing:「あとはdependenciesに追加して、ビルドっと」

project.yml
    dependencies:
      - framework: bar-native-client-sdk-ios/barSDK.xcframework
ld: framework not found barSDK
clang: error: linker command failed with exit code 1 (use -v to see invocation)

:confounded:「ビルドこけた」

project.yml
    sources:
      - path: build
        optional: true

:innocent:「sourceに追加してなかったよ」


参考

12
8
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
12
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?