Created
January 4, 2023 07:58
-
-
Save hassanvfx/10bac1cde426faf580de00738865ab9b to your computer and use it in GitHub Desktop.
Convert Framework into XCFramework Xcode 14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
find "." -name '*.framework' -type d | while read -r FRAMEWORK | |
do | |
echo "-----------------------" | |
FRAMEWORK_NAME=$(echo "$FRAMEWORK" | sed 's/\.\/\(.*\)\.framework/\1/') | |
FRAMEWORK_BUNDLE_NAME=$(/usr/libexec/PlistBuddy -c "Print CFBundleName" "$FRAMEWORK/Resources/Info.plist") || exit | |
XCFRAMEWORK_ROOT="./_$FRAMEWORK_NAME.xcframework" | |
XCTEMP_IPHONE_ROOT="$XCFRAMEWORK_ROOT/iphoneos" | |
XCTEMP_SIMULATOR_ROOT="$XCFRAMEWORK_ROOT/iphonesimulator" | |
TEMP_IPHONE_ROOT="$XCFRAMEWORK_ROOT/iphoneos/$FRAMEWORK_NAME.framework" | |
TEMP_SIMULATOR_ROOT="$XCFRAMEWORK_ROOT/iphonesimulator/$FRAMEWORK_NAME.framework" | |
echo "Bundle Name: $FRAMEWORK_NAME" | |
xcrun lipo -i "$FRAMEWORK/$FRAMEWORK_NAME" | |
echo "Creating new $XCFRAMEWORK_ROOT" | |
rm -rf "$XCFRAMEWORK_ROOT" | |
mkdir "$XCFRAMEWORK_ROOT" | |
echo "Creating new $XCTEMP_IPHONE_ROOT" | |
echo "Creating new $XCTEMP_SIMULATOR_ROOT" | |
mkdir -p "$XCTEMP_IPHONE_ROOT" | |
mkdir -p "$XCTEMP_SIMULATOR_ROOT" | |
echo "cp -r $FRAMEWORK $TEMP_IPHONE_ROOT" | |
echo "cp -r $FRAMEWORK $TEMP_SIMULATOR_ROOT" | |
cp -r "$FRAMEWORK" "$TEMP_IPHONE_ROOT" | |
cp -r "$FRAMEWORK" "$TEMP_SIMULATOR_ROOT" | |
declare -a ARCH_REMOVE_IPHONE=("i386" "x86_64") | |
declare -a ARCH_REMOVE_SIM=("i386" "arm64" "arm64e" "armv7" "armv7s") | |
echo "******************" | |
for ARCH in "${ARCH_REMOVE_IPHONE[@]}" | |
do | |
echo "Remove $ARCH from device slice of the xcframework" | |
xcrun lipo -remove "$ARCH" "$TEMP_IPHONE_ROOT/$FRAMEWORK_NAME" -o "$TEMP_IPHONE_ROOT/tmp" && | |
rm "$TEMP_IPHONE_ROOT/$FRAMEWORK_NAME" && | |
mv "$TEMP_IPHONE_ROOT/tmp" "$TEMP_IPHONE_ROOT/$FRAMEWORK_NAME" | |
done | |
echo "Confirm the DEVICE binary has the proper (arm64) slice" | |
xcrun lipo -i "$TEMP_IPHONE_ROOT/$FRAMEWORK_NAME" | |
echo "******************" | |
for ARCH in "${ARCH_REMOVE_SIM[@]}" | |
do | |
echo "Remove $ARCH from sim slice of the xcframework" | |
xcrun lipo -remove "$ARCH" "$TEMP_SIMULATOR_ROOT/$FRAMEWORK_NAME" -o "$TEMP_SIMULATOR_ROOT/tmp" && | |
rm "$TEMP_SIMULATOR_ROOT/$FRAMEWORK_NAME" && | |
mv "$TEMP_SIMULATOR_ROOT/tmp" "$TEMP_SIMULATOR_ROOT/$FRAMEWORK_NAME" | |
done | |
echo "Confirm the SIM binary has the proper (x86_64) slice." | |
xcrun lipo -i "$TEMP_SIMULATOR_ROOT/$FRAMEWORK_NAME" | |
echo "Create xcframework from the platform slices" | |
echo "xcodebuild -create-xcframework -framework $TEMP_IPHONE_ROOT -framework $TEMP_SIMULATOR_ROOT -output ./$FRAMEWORK_NAME.xcframework" | |
xcodebuild -create-xcframework -framework "$TEMP_IPHONE_ROOT" -framework "$TEMP_SIMULATOR_ROOT" -output "$FRAMEWORK_NAME.xcframework" | |
rm -rf "$XCFRAMEWORK_ROOT" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sample usage: