Skip to content

Instantly share code, notes, and snippets.

@Pulichev
Created September 10, 2019 07:26
Show Gist options
  • Save Pulichev/efa84c10176df9e56fe4eedc5378a5cb to your computer and use it in GitHub Desktop.
Save Pulichev/efa84c10176df9e56fe4eedc5378a5cb to your computer and use it in GitHub Desktop.
Create universal framework
#!/bin/sh
# build-framework-ios.sh
#
set -e # causes the shell to exit if any subcommand or pipeline returns a non-zero status.
set +u
# Avoid recursively calling this script.
if [[ $SF_MASTER_SCRIPT_RUNNING ]] ; then
exit 0
fi
set -u # causes the shell to exit if any undefined variable is referenced, `set +u` turns off
export SF_MASTER_SCRIPT_RUNNING=1
DEBUG=${DEBUG:-0}
export DEBUG
[ $DEBUG -ne 0 ] && set -x # `set -x` shows the commands that get run
# Fully qualified binaries (_B suffix to prevent collisions)
RM_B="/bin/rm"
CP_B="/bin/cp"
MKDIR_B="/bin/mkdir"
LIPO_B="/usr/bin/lipo"
# Constants
CURRENTPATH=`pwd` # Example, specify as you wish.
UNIVERSAL_OUTPUTFOLDER=${CURRENTPATH}/../SharedFrameworks # Specify it
PROJECT_DIR=${CURRENTPATH}
SYMROOT=${PROJECT_DIR}/build
BUILD_DIR=${SYMROOT}
BUILD_ROOT=${SYMROOT}
HERE_INTERMEDIATES=${BUILD_DIR}/Intermediates
OBJROOT=${HERE_INTERMEDIATES}
SYMROOT=${BUILD_DIR}/Products
CONFIGURATION=Release
PRODUCT_NAME=${PRODUCT_NAME}
WORKSPACE_NAME=../!!!YourWorkspaceName!!!.xcworkspace
SCHEME_NAME=InsuranceRelease
IPHONE_SIMULATOR_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator
IPHONE_DEVICE_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos
# Build the simulator platform
echo "building x86_64 i386"
xcodebuild -workspace "${WORKSPACE_NAME}" -scheme "${SCHEME_NAME}" -configuration "${CONFIGURATION}" -sdk iphonesimulator BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_SIMULATOR_BUILD_DIR}" SYMROOT="${SYMROOT}" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" ONLY_ACTIVE_ARCH=NO clean build
# Build the other (non-simulator) platform
echo "building armv7 armv64"
xcodebuild -workspace "${WORKSPACE_NAME}" -scheme "${SCHEME_NAME}" -configuration "${CONFIGURATION}" -sdk iphoneos BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}" SYMROOT="${SYMROOT}" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" ONLY_ACTIVE_ARCH=NO clean build
# Copy the framework structure to the universal folder (clean it first)
#$RM_B -rf "${UNIVERSAL_OUTPUTFOLDER}"
#$MKDIR_B -p "${UNIVERSAL_OUTPUTFOLDER}"
$CP_B -R "${IPHONE_DEVICE_BUILD_DIR}/${PRODUCT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/${PRODUCT_NAME}.framework"
# Smash them together to combine all architectures
echo "smashing together"
$LIPO_B -create "${IPHONE_DEVICE_BUILD_DIR}/${PRODUCT_NAME}.framework/${PRODUCT_NAME}" "${IPHONE_SIMULATOR_BUILD_DIR}/${PRODUCT_NAME}.framework/${PRODUCT_NAME}" -output "${UNIVERSAL_OUTPUTFOLDER}/${PRODUCT_NAME}.framework/${PRODUCT_NAME}"
echo "remove build dir"
$RM_B -rf build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment