Skip to content

Instantly share code, notes, and snippets.

Last active February 19, 2024 10:05
Show Gist options
  • Save quangDecember/6151c0af180a84b79f8b572e289b668f to your computer and use it in GitHub Desktop.
Save quangDecember/6151c0af180a84b79f8b572e289b668f to your computer and use it in GitHub Desktop.
Build XCFramework (universal) framework, create new Aggregate target, add to New Run Script Phase
env > env.txt
instruments -s devices > devices.txt
#! /bin/sh -e
# This script demonstrates archive and create action on frameworks and libraries
# Based on script by @author Boris Bielik
# Release dir path
function archivePathSimulator {
local DIR=${OUTPUT_DIR_PATH}/archives/"${1}-SIMULATOR"
echo "${DIR}"
function archivePathDevice {
local DIR=${OUTPUT_DIR_PATH}/archives/"${1}-DEVICE"
echo "${DIR}"
# Archive takes 3 params
# 1st == SCHEME
# 2nd == destination
# 3rd == archivePath
function archive {
echo "▸ Starts archiving the scheme: ${1} for destination: ${2};\n▸ Archive path: ${3}.xcarchive"
xcodebuild clean archive \
-project "${PROJECT_NAME}.xcodeproj" \
-scheme ${1} \
-configuration ${CONFIGURATION} \
-destination "${2}" \
-archivePath "${3}" \
OBJROOT="${OBJROOT}/DependentBuilds" \
# Builds archive for iOS simulator & device
function buildArchive {
archive $SCHEME "generic/platform=iOS Simulator" $(archivePathSimulator $SCHEME)
archive $SCHEME "generic/platform=iOS" $(archivePathDevice $SCHEME)
# Creates xc framework
function createXCFramework {
xcodebuild -create-xcframework \
-framework ${FRAMEWORK_SIMULATOR_DIR}/${1}.framework \
-framework ${FRAMEWORK_DEVICE_DIR}/${1}.framework \
-output ${OUTPUT_DIR_PATH}/xcframeworks/${1}.xcframework
### Static Libraries cant be turned into frameworks
function createXCFrameworkForStaticLibrary {
xcodebuild -create-xcframework \
-library ${LIBRARY_SIMULATOR_DIR}/libStaticLibrary.a \
-library ${LIBRARY_DEVICE_DIR}/libStaticLibrary.a \
-output ${OUTPUT_DIR_PATH}/xcframeworks/${1}.xcframework
echo "#####################"
echo "▸ Cleaning the dir: ${OUTPUT_DIR_PATH}"
#### Static Library ####
#echo "▸ Archive $LIBRARY"
#buildArchive ${LIBRARY}
#echo "▸ Create $FRAMEWORK.xcframework"
#createXCFrameworkForStaticLibrary ${LIBRARY}
#### Dynamic Framework ####
echo "▸ Archive $DYNAMIC_FRAMEWORK"
echo "▸ Create $DYNAMIC_FRAMEWORK.xcframework"
createXCFramework ${DYNAMIC_FRAMEWORK}
Copy link

tulssinep commented Jul 6, 2020

Hey, is this supposed to run as an Xcode Run Script phase? If so, what Xcode version? On 11.3 it gets stuck on Using build description from memory

Sorry I think I ran it from the wrong target. Thank you for the Gist I think it is working correctly

Copy link

It's not working with Xcode 12, can any one help?

Copy link

It's not working with Xcode 12, can any one help?

Hi @DineshKachhot, there is a missing part to exclude build ARCHs of Apple Silicon Mac. I don't remember the exact syntax. Maybe @dj110r and @21DerickDerick can help

Copy link

I would like add two two steps to do before run this script, change you Build settings like follow,
Skip install - NO
Build libraries for distribution - YES

Though it is already added in the script, in my case it was not working.

Copy link

Now I am getting following error for one of the files from my library,

..../MPUtil.m normal armv7 objective-c

Copy link

AbhijitPatilSafexpay commented Aug 5, 2021

invalid argument 'Project'.
When i am trying to run this build phase script

Copy link

Works great, thank you.

Xcode Version 13.4.1 (13F100)

Copy link

hitendradeveloper commented Dec 15, 2022

This worked perfect for me. XCode 14.1
Make sure

  1. you add aggregate target
  2. add the run script.
  3. Build the newly added target

If you add run script in existing target -- multiple failures will be occured.

  • you can see error like name.xcodeproj does not exists
  • XCode can stuck with Using build description from memory
  • XCode build process can go in recursive/infinite loop

Copy link

Tj3n commented Feb 21, 2023

I got issue error: binaries with multiple platforms are not supported, the architecture of the binary in -SIMULATOR.xcarchive one seems to contains arm64 & x86_64 (maybe this is the issue?). Can someone help me on this? Thanks!

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