Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This run script will build the iphoneos and iphonesimulator schemes and then combine them into a single framework using the lipo tool.
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# 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}" -configuration ${CONFIGURATION} -sdk iphonesimulator -arch x86_64 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}"
@mizutori

This comment has been minimized.

Copy link

commented Oct 20, 2014

Hi @cconway25, Thank you for sharing this!
I have one question.
Both iphonesimulator and iphoneos framework directory have "Modules" directory inside.
We don't need to combine the content of these two "Modules" directories ?

@patricia-idair

This comment has been minimized.

Copy link

commented Oct 27, 2014

Thanks, cconway25. After adding this script to a Universal Framework, should I see Debug-iphonesuniversal as well as Debug-iphoneos and Debug-iphonesimulator? I've been using Universal Frameworks with previous versions and having some trouble converting to Xcode 6. Ah-ha! I forgot to select the Aggregate scheme to build and run! But I'm still having issues with the build script:

fatal error: lipo: can't open input file: /Users/pdl/Library/Developer/Xcode/DerivedData/License-blnxjfvoxnqfelftmzojgdwhvazk/Build/Products/Debug-iphonesimulator/License.framework/License (No such file or directory)

@mxcl

This comment has been minimized.

Copy link

commented Nov 4, 2014

Indeed, I had to merge the modules folder in order to produce a valid framework.

@skywinder

This comment has been minimized.

Copy link

commented Apr 15, 2015

@cconway25 wow! Thanks, it's awesome!

FYI: here is modifed script to support swift also by @cromandini :
https://gist.github.com/cromandini/1a9c4aeab27ca84f5d79

@skywinder

This comment has been minimized.

Copy link

commented Apr 15, 2015

bdw: I try to run this script with Xcode 6.3 and have some strange behaviour - it hangs and start to run this script in infinite loop. Have no idea, whats goes wrong. :(

@skywinder

This comment has been minimized.

Copy link

commented Apr 15, 2015

It seems, that it not works with xcworkspace. And unfortunately there is no way to get Scheme name from Xcode Build Settings. If someone found solution - please - let me know!

@holiday

This comment has been minimized.

Copy link

commented Jan 14, 2016

Thanks for this! Finally got both iphoneos and simulator working fine!

@newMobileStar

This comment has been minimized.

Copy link

commented Mar 22, 2016

Thanks for this

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.