Well, universal frameworks are really a pain. Not only for iOS and OSX, but only for iOS, as you need 2 frameworks: one for the simulator and one for the devices. How you work with iOS is an โaggregateโ goal. I believe that the same path can be used to integrate the OS X target.
When you create the framework, you get the folder.framework (lego block). There are 2 very important things:
- Executable file
- Folder "Modules"
In both of these cases, you must have an implementation to support all the architectures that you want to support. If you want to create your own frameworks separately and want to combine them together, you will have to do the following:
- Take both executables and merge them using the lipo command.
- Ensure that all files in the Modules folder are moved together.
In practical terms, this is a mess, so here's what I do!
- First I build the framework. They may have different goals in the same project, but usually the same name helps. Only for iOS there is only one framework, so just one goal is enough.
- Then I add the Aggregate target, it will help to create several assemblies for different architectures.
- By clicking on the project name and then on the Aggregate target, I go to "Build Phases" and click on a small plus to add the "Phase of the new startup script".
- There I copy and paste the code into this GIST.
- Finally, changing your scheme to Aggregate target and creating it will result in the necessary merging, and you will get a universal framework structure.
The scenario is quite simple, and after playing a little, Iโm sure that it can be changed by adding OSX support to it. I hope this points you in the right direction :)
Scenario Content:
#!/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 directory cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}" # Step 6. Convenience step to open the project directory in Finder open "${PROJECT_DIR}"
source share