Skip to content

Instantly share code, notes, and snippets.

@AKosmachyov
Last active March 25, 2022 13:15
Show Gist options
  • Save AKosmachyov/890974ada314efda098e1d689fec9d2c to your computer and use it in GitHub Desktop.
Save AKosmachyov/890974ada314efda098e1d689fec9d2c to your computer and use it in GitHub Desktop.
Split FAT .framework

The architectures can be shown using lipo -i

$ xcrun lipo -i INSCoreMedia.framework/INSCoreMedia
# Architectures in the fat file: INSCoreMedia.framework/INSCoreMedia are: armv7 i386 x86_64 arm64 
  • arm64 - is the current 64-bit ARM CPU architecture, as used since the iPhone 5S and later (6, 6S, SE and 7), the iPad Air, Air 2 and Pro, with the A7 and later chips.
  • armv7s - being used in Apple's A6 and A6X chips on iPhone 5, iPhone 5C and iPad 4.
  • armv7 - an older variation of the 32-bit ARM CPU, as used in the A5 and earlier.
  • i386 - (i.e. 32-bit Intel) is the only option on iOS 6.1 and below.
  • x86_64 is the architecture of Intel's 64-bit CPUs, sometimes also simply referred to as x64. It is the architecture for all Intel Macs shipped between 2005 and 2021 and iPhone simulators. More details

Create 2 folders with framework copy

# Create directories
$ mkdir iphoneos
$ mkdir iphonesimulator

# Copy framework into the platform specific directories
$ cp -R INSCoreMedia.framework iphoneos/INSCoreMedia.framework
$ cp -R INSCoreMedia.framework/ iphonesimulator/INSCoreMedia.framework
# The -R flag causes cp to copy the folder and its contents.

Slice unused architecture for real device

# Remove slices that aren't relevant to the device slice of the xcframework
$ xcrun lipo -remove i386 -remove x86_64 -remove armv7 ./iphoneos/INSCoreMedia.framework/INSCoreMedia -o ./iphoneos/INSCoreMedia.framework/INSCoreMedia

# Confirm the binary has the proper (arm64) slice
$ xcrun lipo -i iphoneos/INSCoreMedia.framework/INSCoreMedia

Slice unused architecture for Simulator

# Remove slices that aren't relevant to the simulator slice of the xcframework
$ xcrun lipo -remove i386 -remove arm64 -remove armv7 ./iphonesimulator/INSCoreMedia.framework/INSCoreMedia -o ./iphonesimulator/INSCoreMedia.framework/INSCoreMedia

# Confirm the binary has the proper (x86_64) slice.
$ xcrun lipo -i iphonesimulator/INSCoreMedia.framework/INSCoreMedia

Combine the two slices into an XCFramework using xcodebuild -create-xcframework.

$ xcodebuild -create-xcframework -framework iphoneos/INSCoreMedia.framework/ -framework iphonesimulator/INSCoreMedia.framework/ -output "INSCoreMedia.xcframework"

Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment