Skip to content

Instantly share code, notes, and snippets.

@KaQuMiQ
Created January 19, 2021 12:02
Show Gist options
  • Save KaQuMiQ/5c02a27c736188e75d750c630cb9eb90 to your computer and use it in GitHub Desktop.
Save KaQuMiQ/5c02a27c736188e75d750c630cb9eb90 to your computer and use it in GitHub Desktop.
Convert fat binary framework into XCFramework
#! /bin/bash
mkdir ./arm64
mkdir ./x86_64
find "./" -name '*.framework' -type d | while read -r FRAMEWORK
do
echo "Preparing framework: $FRAMEWORK"
FRAMEWORK_EXECUTABLE_NAME=$(/usr/libexec/PlistBuddy -c "Print CFBundleExecutable" "$FRAMEWORK/Info.plist")
echo "Preparing arm64 framework"
cp -R "$FRAMEWORK" "./arm64/$FRAMEWORK_EXECUTABLE_NAME.framework"
rm "./arm64/$FRAMEWORK_EXECUTABLE_NAME.framework/$FRAMEWORK_EXECUTABLE_NAME"
$(/usr/libexec/PlistBuddy -c "Set CFBundleSupportedPlatforms iPhoneOS" "./arm64/$FRAMEWORK_EXECUTABLE_NAME.framework/Info.plist")
echo "Extracting arm64 from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "arm64" "$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME" -o "./arm64/$FRAMEWORK_EXECUTABLE_NAME.framework/$FRAMEWORK_EXECUTABLE_NAME"
echo "Preparing x86_64 framework"
cp -R "$FRAMEWORK" "./x86_64/$FRAMEWORK_EXECUTABLE_NAME.framework"
rm "./x86_64/$FRAMEWORK_EXECUTABLE_NAME.framework"
$(/usr/libexec/PlistBuddy -c "Set CFBundleSupportedPlatforms iPhoneSimulator" "./x86_64/$FRAMEWORK_EXECUTABLE_NAME.framework/Info.plist")
echo "Extracting x86_64 from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "x86_64" "$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME" -o "./x86_64/$FRAMEWORK_EXECUTABLE_NAME.framework/$FRAMEWORK_EXECUTABLE_NAME"
xcodebuild -create-xcframework -framework "./arm64/$FRAMEWORK_EXECUTABLE_NAME.framework" -framework "./x86_64/$FRAMEWORK_EXECUTABLE_NAME.framework" -output "$FRAMEWORK_EXECUTABLE_NAME.xcframework" || exit -1
done
rm -r ./arm64
rm -r ./x86_64
@dancarvajc
Copy link

dancarvajc commented Oct 2, 2024

What when the framework contains resources? Are they also transferred to the XCFramework? Cannot see any references.

@Blackjacx I have the same question, is there any way to convert the fat binary with resources to XCFramework including arm64-simulator slice?

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