Last active
July 9, 2024 06:29
-
-
Save pwc3/09b5dc326837e210b73daa63cd13503e to your computer and use it in GitHub Desktop.
Convert Legacy Framework to XCFramework
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
#!/usr/bin/env bash | |
# Converts a legacy framework into an xcframework. | |
# Usage: convert-framework.sh input_framework output_xcframework | |
set -euo pipefail | |
E_BADARGS=85 | |
if [ $# -ne 2 ]; then | |
echo "Usage: $(basename $0) framework xcframework" | |
exit $E_BADARGS | |
fi | |
# The source framework directory | |
framework_dir="$1" | |
# The destination xcframework location | |
xcframework="$2" | |
# Extract the basename of the framework, stripping off the path and leaving only Foo.framework | |
framework_basename="$(basename -- "$framework_dir")" | |
# Extract the name of the framework, leaving only Foo | |
framework_name="${framework_basename%.*}" | |
# Make a temporary working directory | |
tmpdir="$(mktemp -d ${TMPDIR:-/tmp}/convert-framework.XXXXXX)" | |
echo "Working directory: $tmpdir" | |
# This is based on an approach recommended here: | |
# https://github.com/twilio/twilio-voice-ios/issues/64#issuecomment-747186499 | |
mkdir "$tmpdir/arm64" | |
mkdir "$tmpdir/x86_64" | |
cp -R "$framework_dir" "$tmpdir/arm64/$framework_basename" | |
cp -R "$framework_dir" "$tmpdir/x86_64/$framework_basename" | |
echo "Extracting arm64 from framework" | |
pushd "$tmpdir/arm64" > /dev/null | |
lipo \ | |
-extract arm64 \ | |
-output "$framework_basename/$framework_name" \ | |
"$framework_basename/$framework_name" | |
echo "Updating CFBundleSupportedPlatforms in arm64/$framework_basename/Info.plist" | |
plutil \ | |
-replace CFBundleSupportedPlatforms \ | |
-xml "<array><string>iPhoneOS</string></array>" \ | |
"$framework_basename/Info.plist" | |
popd > /dev/null | |
echo "Extracting x86_64 from framework" | |
pushd "$tmpdir/x86_64" > /dev/null | |
lipo \ | |
-extract x86_64 \ | |
-output "$framework_basename/$framework_name" \ | |
"$framework_basename/$framework_name" | |
echo "Updating CFBundleSupportedPlatforms in x86_64/$framework_basename/Info.plist" | |
plutil \ | |
-replace CFBundleSupportedPlatforms \ | |
-xml "<array><string>iPhoneSimulator</string></array>" \ | |
"$framework_basename/Info.plist" | |
popd > /dev/null | |
echo "Building xcframework at $xcframework" | |
xcodebuild \ | |
-create-xcframework \ | |
-framework "$tmpdir/arm64/$framework_basename" \ | |
-framework "$tmpdir/x86_64/$framework_basename" \ | |
-output "$xcframework" | |
echo "Done" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment