Skip to content

Instantly share code, notes, and snippets.

@tuantmdev
Created November 6, 2015 04:46
Show Gist options
  • Save tuantmdev/5c697c7525f54bd246b4 to your computer and use it in GitHub Desktop.
Save tuantmdev/5c697c7525f54bd246b4 to your computer and use it in GitHub Desktop.
Script to build universal framework (Simulator and device support)
#!/bin/sh
#######################################
# Step 0. Prepare framework
# - Open Build Settings, Change Mach-O Type -> Static Library
# - Add User-Defined Settings with key "CODE_SIGNING_REQUIRED" and value "NO" (Without quote)
# - Add these item to Architectures key i386, armv7, armv7s, x86_64, arm64
# - Create new target with Aggregate template
# - Open Build Phases of Aggregate template. Set framework target above as Dependency target
# - Add run script to run this file
########################################
UNIVERSAL_OUTPUTFOLDER=../build/
# make the output directory and delete the framework directory
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
rm -rf "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework"
# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# Step 2. Copy the framework structure to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
# Step 3. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
@MrBoog
Copy link

MrBoog commented Jan 29, 2021

Looks good, but I got one question: do I have to create an Aggregate template and Set the framework target as dependency target manually? can I do all those stuff with one script?

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