Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kientux/8ed105dddc99382707ecc82b619db1da to your computer and use it in GitHub Desktop.
Save kientux/8ed105dddc99382707ecc82b619db1da 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"
@kientux
Copy link
Author

kientux commented Feb 23, 2017

Fork to:

  • Remove hardcoded values
  • Make xcodebuild build the project into ${SYMROOT} (usually derived data folder) instead of default location (${SRCROOT}/build)
  • Open destination folder when done

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