Skip to content

Instantly share code, notes, and snippets.

@Claes34
Last active March 19, 2021 10:37
Show Gist options
  • Save Claes34/04b8ecc138790b7bbbccc5f99d5938cf to your computer and use it in GitHub Desktop.
Save Claes34/04b8ecc138790b7bbbccc5f99d5938cf to your computer and use it in GitHub Desktop.
Having problems with .framework on Xcode12.X ? Make a nice XCFramework from your old universal .framework to solve it. (To fully support arm64 simulators, framework providers have to provide a legit xcframework, M1 users, we shall use rosetta for now)
### CREATED BY NICOLAS FONTAINE ON 18/03/2021 ###
#!/bin/sh
set -o errexit
finish()
{
rm -rf iphoneos
rm -rf iphonesimulator
}
trap finish EXIT
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "options:"
echo "-h, --help show brief help"
echo "-i, --input=INPUT_PATH specify an input framework to transform"
echo "-o, --output=OUTPUT_DIR specify a directory to store output in"
exit 0
;;
-i)
shift
if test $# -gt 0; then
export INPUT_PATH=$1
else
echo "no input specified, use -i <your_framework_path>"
exit 1
fi
shift
;;
--input*)
export INPUT_PATH=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-o)
shift
if test $# -gt 0; then
export OUTPUT_DIR=$1
else
echo "no output dir specified, use -o <path_to_output_dir>"
exit 1
fi
shift
;;
--output*)
export OUTPUT_DIR=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
*)
break
;;
esac
done
if [ -z "$INPUT_PATH" ]; then
echo "no input given, use -i <your_framework_path>"
exit 1
elif [ -z "$OUTPUT_DIR" ]; then
echo "no output given, use -o <path_to_output_dir>"
exit 1
fi
rm -rf iphoneos
rm -rf iphonesimulator
mkdir -p iphoneos
mkdir -p iphonesimulator
FRAMEWORK_NAME="$(basename $INPUT_PATH .framework)"
FRAMEWORK_FILE="$(basename $INPUT_PATH)"
echo "Transforming $FRAMEWORK_NAME to xcframework, please wait...\n"
SOURCE_ARCHITECTURES_RAW="$(lipo -info $INPUT_PATH/$FRAMEWORK_NAME)"
SOURCE_ARCHITECTURES=${SOURCE_ARCHITECTURES_RAW##*:}
echo "SOURCE CONTAINS ARCHITECTURES : $SOURCE_ARCHITECTURES\n"
IFS=' ' read -r -a ARCHITECTURES <<< "$SOURCE_ARCHITECTURES"
# Copy framework into the platform specific directories
cp -R $INPUT_PATH iphoneos/$FRAMEWORK_FILE
cp -R $INPUT_PATH iphonesimulator/$FRAMEWORK_FILE
### LOOPING TO REMOVE UNWANTED ARCHITECTURES FOR IPHONEOS
for ARCH in "${ARCHITECTURES[@]}"; do
if [ $ARCH != "arm64" ] && [ $ARCH != "armv7" ]; then
echo "Removing $ARCH for iphoneos framework"
xcrun lipo -remove $ARCH ./iphoneos/$FRAMEWORK_FILE/$FRAMEWORK_NAME -o ./iphoneos/$FRAMEWORK_FILE/$FRAMEWORK_NAME
fi
done
### LOOPING TO REMOVE UNWANTED ARCHITECTURES FOR IPHONE SIMULATOR
for ARCH in "${ARCHITECTURES[@]}"; do
if [ $ARCH != "x86_64" ] && [ $ARCH != "i386" ]; then
echo "Removing $ARCH for iphonesimulator framework"
xcrun lipo -remove $ARCH ./iphonesimulator/$FRAMEWORK_FILE/$FRAMEWORK_NAME -o ./iphonesimulator/$FRAMEWORK_FILE/$FRAMEWORK_NAME
fi
done
### EDITING INFO.PLIST OF OUTPUT
/usr/libexec/PlistBuddy -c "Set DTPlatformName iphoneOS" ./iphoneos/$FRAMEWORK_FILE/Info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleSupportedPlatforms:0 iphoneOS" ./iphoneos/$FRAMEWORK_FILE/Info.plist
/usr/libexec/PlistBuddy -c "Set DTPlatformName iphonesimulator" ./iphonesimulator/$FRAMEWORK_FILE/Info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleSupportedPlatforms:0 iphoneSimulator" ./iphonesimulator/$FRAMEWORK_FILE/Info.plist
echo "\nMerging to xcframework at $OUTPUT_DIR"
rm -rf $OUTPUT_DIR/$FRAMEWORK_NAME.xcframework
xcodebuild -create-xcframework \
-framework ./iphoneos/$FRAMEWORK_FILE \
-framework ./iphonesimulator/$FRAMEWORK_FILE/ \
-output $OUTPUT_DIR/$FRAMEWORK_NAME.xcframework
echo "--------- ALL DONE ---------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment