My company\'s iOS framework is meant to work on a real iOS device. Said framework is currently generated as an additional target within a Xcode project which also generates
build iOS/tvOS universal/fat framework
https://github.com/unchartedworks/universalbuild
Usage:
universalbuild (-p|--project name.xcodeproj) (-s|--scheme schemename) (-c|--configuration configurationname)
Example:
git clone https://github.com/cruisediary/Pastel.git
cd Pastel
universalbuild -p ./Pastel.xcodeproj -s Pastel -c Debug
Run script to create universal framework (no recursion issue)
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Next, work out if we're in SIM or DEVICE
if [ "false" == ${ALREADYINVOKED:-false} ]
then
export ALREADYINVOKED="true"
if [ ${PLATFORM_NAME} = "iphonesimulator" ]
then
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
else
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
fi
# 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 (if it exists) to the copied framework directory
SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/."
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule"
fi
# 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}"
fi
I too struggled with the same issue. I had a series of cocoapods that were used as source pods, but needed to be converted into binary pods. Between lots of googling, trial and error and hacking, I came up with a script that I have had great success with. It is based on the scripts you see here, but refactored into functions and some debugging output (that goes into the logs in /tmp) when something is missing.
That script can be found as a github gist here: https://gist.github.com/intere/bc380fa45ccf23976d3fc297522d29a8
FWIW, I've been using Xcode 9 (9.2, then 9.3, and now 9.4).
It is possible since I am currently developing universal frameworks on iOS, watchOS and tvOS on Xcode 8.
The way I do it is creating an Aggregate target(cross platform) and add a run script in its build phase. The script basically compiles the iOS target for iphonesimulator and iphoneos
After this it creates a new binary merging both of them(lipo -create -output)
Would you mind posting your current build script for generating a universal framework so I can guide you with what you are doing wrong?
Take in consideration that the script could not be your issue here, your issue could be setting up your valid architectures, your architectures or even how you are signing the target. I recommend for now, to leave the Automatically manage signing option in your General settings of your target unchecked, and set your provisioning profiles and certs manually.
Run script:
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}/iOS"
# Step 1. Build Device and Simulator versions on iOS
xcodebuild -workspace "${PROJECT_NAME}.xcworkspace" -scheme "${PROJECT_NAME}" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' clean build
xcodebuild -workspace "${PROJECT_NAME}.xcworkspace" -scheme "${PROJECT_NAME}" -sdk iphoneos 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}/iOS"
# Step 3. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/iOS/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
# Step 4. Convenience step to copy the framework to the project's directory
mkdir -p "${TMPDIR}/${PROJECT_NAME}/Frameworks/iOS"
cp -R "${UNIVERSAL_OUTPUTFOLDER}/iOS/${PROJECT_NAME}.framework" "${TMPDIR}/${PROJECT_NAME}/Frameworks/iOS"
# Step 6. Create .tar.gz file for posting on the binary repository
cd "${TMPDIR}"
# We nest the framework inside a Frameworks folder so that it unarchives correctly
tar -zcf "${PROJECT_NAME}.framework.tar.gz" "${PROJECT_NAME}/Frameworks/"
mv "${PROJECT_NAME}.framework.tar.gz" "${PROJECT_DIR}/"
# Step 7. Convenience step to open the project's directory in Finder
#open "${PROJECT_DIR}"
Take in consideration that I set the Build Active Architecture Only to NO in the build settings, also the valid Architectures are set as arm64, x86_64, i386, armv7, armv7s. The Architectures are ${ARCHS_STANDARD} armv7s.
I also set a user defined build setting BITCODE_GENERATION_MODE bitcode. With this build setting I make sure to generate binaries with bitcode enabled.