Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Build a universal iOS framework/library
#!/bin/bash
set -e
# required arguments:
# WORKSPACE_DIR=Networking.xcworkspace
# SCHEME_NAME=Networking
# PRODUCT_NAME=Networking
CONFIGURATION=Release
BUILD_DIR="$(pwd)/Build/${PRODUCT_NAME}"
BUILD_ROOT="${BUILD_DIR}"
UNIVERSAL_OUTPUTFOLDER="${BUILD_DIR}/${CONFIGURATION}-Universal"
rm -Rf "$BUILD_ROOT"
xcodebuild \
-workspace "${WORKSPACE_DIR}" \
-scheme "${SCHEME_NAME}" \
-configuration "${CONFIGURATION}" \
-sdk iphoneos \
BUILD_DIR="${BUILD_DIR}" \
BUILD_ROOT="${BUILD_ROOT}" \
clean build
xcodebuild \
-workspace "${WORKSPACE_DIR}" \
-scheme "${SCHEME_NAME}" \
-configuration "${CONFIGURATION}" \
-sdk iphonesimulator \
BUILD_DIR="${BUILD_DIR}" \
BUILD_ROOT="${BUILD_ROOT}" \
clean build
# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
cp -R \
"${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PRODUCT_NAME}.framework" \
"${UNIVERSAL_OUTPUTFOLDER}/${PRODUCT_NAME}.framework"
# Step 3. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
cp -R \
"${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PRODUCT_NAME}.framework/Modules/${PRODUCT_NAME}.swiftmodule/." \
"${UNIVERSAL_OUTPUTFOLDER}/${PRODUCT_NAME}.framework/Modules/${PRODUCT_NAME}.swiftmodule"
# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create \
-output "${UNIVERSAL_OUTPUTFOLDER}/${PRODUCT_NAME}.framework/${PRODUCT_NAME}" \
"${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PRODUCT_NAME}.framework/${PRODUCT_NAME}" \
"${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PRODUCT_NAME}.framework/${PRODUCT_NAME}"
open "${UNIVERSAL_OUTPUTFOLDER}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.