Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karosLi/9c0ac1e83c432bded6872ea7798e5bb7 to your computer and use it in GitHub Desktop.
Save karosLi/9c0ac1e83c432bded6872ea7798e5bb7 to your computer and use it in GitHub Desktop.
Merge simulator and device dynamic frameworks into one
# Merge Script
# 1
# Set bash script to exit immediately if any commands fail.
set -e
# 2
# Setup some constants for use later on.
FRAMEWORK_NAME="${PROJECT_NAME}"
# 3
# If remnants from a previous build exist, delete them.
if [ -d "${SYMROOT}" ]; then
echo "${SYMROOT}"
rm -rf "${SYMROOT}"
fi
# 4
# Build the framework for device and for simulator (using all needed architectures).
xcodebuild -target "${FRAMEWORK_NAME}" SYMROOT="$SYMROOT" -configuration Release -arch arm64 -arch armv7 -arch armv7s only_active_arch=no defines_module=yes -sdk "iphoneos"
xcodebuild -target "${FRAMEWORK_NAME}" SYMROOT="$SYMROOT" -configuration Release -arch x86_64 -arch i386 only_active_arch=no defines_module=yes -sdk "iphonesimulator"
# 5
# Copy the device version of framework to build dir.
cp -r "${SYMROOT}/Release-iphoneos/${FRAMEWORK_NAME}.framework" "${SYMROOT}/${FRAMEWORK_NAME}.framework"
# 6
# Replace the framework executable within the framework with
# a new version created by merging the device and simulator
# frameworks' executables with lipo.
lipo -create -output "${SYMROOT}/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${SYMROOT}/Release-iphoneos/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${SYMROOT}/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}"
# 7
# Copy the Swift module mappings for the simulator into the
# framework. The device mappings already exist from step 5.
cp -r "${SYMROOT}/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule/" "${SYMROOT}/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule"
open "$SYMROOT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment