Last active
January 4, 2022 13:22
-
-
Save berkakkerman/14b0b6e49e6862b6ce738eab0d57449b to your computer and use it in GitHub Desktop.
Universal(iOS + iOS Simulator) framework generation script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal | |
echo "Universal(iOS + iOS Simulator) framework generation started" | |
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" | |
echo "Output directory created at ${UNIVERSAL_OUTPUTFOLDER}" | |
echo "Step 1. Build Device version" | |
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build -quiet | |
echo "Step 1 completed" | |
echo "Step 2. Build simulator version" | |
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" EXCLUDED_ARCHS="arm64" clean build -quiet | |
echo "Step 2 completed" | |
echo "Step 3. Copy the framework structure (from iphoneos build) to the universal folder" | |
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/" | |
echo "Step 3 completed" | |
echo "Step 4. 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/." | |
echo "Step 4 completed" | |
echo "Step 5. Merge device and simulator .swiftmodule files" | |
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then | |
cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule" | |
fi | |
echo "Step 5 completed" | |
echo "Step 6. 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}" | |
echo "Step 6 completed" | |
cd "${PROJECT_DIR}" | |
mkdir -p build | |
DESTINATION_FOLDER="${PROJECT_DIR}/build" | |
echo "Step 7. Convenience step to copy the framework to the project's directory" | |
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${DESTINATION_FOLDER}" | |
echo "Step 7 completed" | |
echo "Generation process completed successfully" | |
echo "Framework is ready at ${DESTINATION_FOLDER}" | |
open "${DESTINATION_FOLDER}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment