Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
iOS Generate Universal Framework
# For actual device testing, disabled the script running by uncomment following two lines.
##########################################################################################
#echo "SCRIPT RUNNING ABORTED. COMMENT THIS OUT TO GENERATE UNIVERSAL FRAMEWORK"
#exit 0
##########################################################################################
set -e
set +u
# Avoid recursively calling this script.
if [[ $SF_MASTER_SCRIPT_RUNNING ]]
then
exit 0
fi
set -u
export SF_MASTER_SCRIPT_RUNNING=1
#testing
#echo "Started Running Script ...."
# Constants
SF_TARGET_NAME=${PROJECT_NAME}
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
#PROJECT_FILE_PATH="${PROJECT_DIR}/${PROJECT_NAME}"
#PROJECT_FILE_PATH="${SRCROOT}/${PROJECT_NAME}"
XCODEPROJ=`find . -name '*.xcodeproj'`
echo "XCODEPROJ:${XCODEPROJ}"
echo "UNIVERSAL OUTPUT FOLDER : ${XCODEPROJ}"
PROJECT_FILE_PATH="${XCODEPROJ}"
# Take build target
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]
then
SF_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi
if [[ "$SF_SDK_PLATFORM" = "iphoneos" ]]
then
echo "Please choose iPhone simulator as the build target."
exit 1
fi
IPHONE_DEVICE_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos
# Build the other (non-simulator) platform
echo "Build the other (non-simulator) platform"
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk iphoneos BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}/arm64" SYMROOT="${SYMROOT}" ARCHS="arm64" VALID_ARCHS="arm64" $ACTION
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk iphoneos BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}/armv7" SYMROOT="${SYMROOT}" ARCHS="armv7 armv7s" VALID_ARCHS="armv7 armv7s" $ACTION
# Copy the framework structure to the universal folder (clean it first)
echo "Copy the framework structure to the universal folder (clean it first)."
rm -rf "${UNIVERSAL_OUTPUTFOLDER}"
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${TARGET_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework"
# Smash them together to combine all architectures
echo "Smash them together to combine all architectures."
lipo -create "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${TARGET_NAME}.framework/${TARGET_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/arm64/${TARGET_NAME}.framework/${TARGET_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/armv7/${TARGET_NAME}.framework/${TARGET_NAME}" -output "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/${TARGET_NAME}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment