Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to put in an Aggregate Target of a Framework in Xcode 6 to create a Universal Framework
#!/bin/sh
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 ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
# Step 3. Copy Swift modules (from iphonesimulator build) to the copied framework directory
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/." "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_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}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
# Step 5. Convenience step to copy the framework to the project's directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"
# Step 6. Convenience step to open the project's directory in Finder
open "${PROJECT_DIR}"
@hons82

This comment has been minimized.

Copy link

commented Mar 25, 2015

Hi,
if I aggregate my framework with this script I can run it on a device, but not in the simulator.
Am I doing something wrong?
thx
~Hannes

@TobiasSeitz

This comment has been minimized.

Copy link

commented Apr 5, 2015

Hi,

thanks a lot for the script.
I have the same problem as hons82.

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_SomeClass", referenced from:
      objc-class-ref in AppDelegate.o
      objc-class-ref in FirstViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

lipo succeeds without errors.
I'm not using Swift, which is why I removed Step 3.
I use CocoaPods AFNetworking and FMDB in my Framework, so maybe that's the problem.

If I make any progress on this, I'll let you know. Please do the same ;)

@Tokuriku

This comment has been minimized.

Copy link
Owner Author

commented May 15, 2015

Hi guys,

There have been updates to Xcode and I haven't had time to retest this but..

Step 3 moves the simulator modules to the main framework folder before the lipo. You really don't want to skip this step. That said you will want to use something else than swiftmodule in
'framework/Modules/${PROJECT_NAME}.swiftmodule/'

I don't code in Objective-C so I don't know the right file format to append there but you should find it easily by going to that folder manually and looking at what the extension is for the modules..

@kainy-priyadarshini

This comment has been minimized.

Copy link

commented Jun 27, 2019

Hi I have used the same script but still not able to run on simulator. Can any one please help

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.