-
-
Save atsepkov/1673c2d899470270e3eb313912aafc6f to your computer and use it in GitHub Desktop.
exec > /tmp/${PROJECT_NAME}_archive.log 2>&1 | |
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal | |
if [ "true" == ${ALREADYINVOKED:-false} ] | |
then | |
echo "RECURSION: Detected, stopping" | |
else | |
export ALREADYINVOKED="true" | |
# make sure the output directory exists | |
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" | |
echo "Building for iPhoneSimulator" | |
xcodebuild -workspace "${WORKSPACE_PATH}" -scheme "${SCHEME_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' ONLY_ACTIVE_ARCH=NO ARCHS='i386 x86_64' BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" BITCODE_GENERATION_MODE=bitcode clean build | |
# Step 1. Copy the framework structure (from iphoneos build) to the universal folder | |
echo "Copying to output folder" | |
cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${FULL_PRODUCT_NAME}" "${UNIVERSAL_OUTPUTFOLDER}/" | |
# Step 2. 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 3. Create universal binary file using lipo and place the combined executable in the copied framework directory | |
echo "Combining executables" | |
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${EXECUTABLE_PATH}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${EXECUTABLE_PATH}" "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${EXECUTABLE_PATH}" | |
# Step 4. Create universal binaries for embedded frameworks | |
for SUB_FRAMEWORK in $( ls "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Frameworks" ); do | |
BINARY_NAME="${SUB_FRAMEWORK%.*}" | |
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Frameworks/${SUB_FRAMEWORK}/${BINARY_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${SUB_FRAMEWORK}/${BINARY_NAME}" "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${PROJECT_NAME}.framework/Frameworks/${SUB_FRAMEWORK}/${BINARY_NAME}" | |
done | |
# Step 5. Convenience step to copy the framework to the project's directory | |
echo "Copying to project dir" | |
yes | cp -Rf "${UNIVERSAL_OUTPUTFOLDER}/${FULL_PRODUCT_NAME}" "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}" | |
fi |
try to give answer to my STO question about creating framework from terminal.
no work in Xcode 9
The skip install is a vital step in this script, if its YES, the ${ARCHIVE_PRODUCTS_PATH} is /Library, and if it is NO, this is set to proper folder to get the framework. Checked on Xcode 9.
Kudos to author.
Can this be updated for Xcode 10?
Doesn't work in Xcode 10.
This does work for me in Xcode 9.4.1 but not Xcode 10. The cause of the issue seems to be a new build system in Xcode 10: https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes/build_system_release_notes_for_xcode_10
As a temporary workaround in Xcode 10, you can set the build system to 'Legacy Build System' in the File menu > Workspace Settings. I would not expect this setting to remain available forever.
@dmdeller there's also an Apple Dev Forum thread on that topic, with this comment down below showing an automated solution
Hello, I have a problem that unless Bitcode is set to NO the script does not generate the binaries for the simulator and if the bitcode is enabled when I add my framework to a test app I have an error that says bitcode was not enabled by the creator of this framework.