Last active
June 6, 2024 10:02
-
-
Save sinbadbd/285dc3023214993aa2b30be0ac6531c2 to your computer and use it in GitHub Desktop.
XCFramework Build
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/bash | |
# Define variables | |
SCHEME="FWTest" | |
PROJECT_DIR=$(pwd) | |
ARCHIVE_PATH="$PROJECT_DIR/build/xcf" | |
DERIVED_DATA_PATH="$PROJECT_DIR/build/derived_data" | |
DEVICE_ARCHIVE_PATH="$ARCHIVE_PATH/ios.xcarchive" | |
SIMULATOR_ARCHIVE_PATH="$ARCHIVE_PATH/iossimulator.xcarchive" | |
XCFRAMEWORK_OUTPUT_PATH="$PROJECT_DIR/build/FWTest.xcframework" | |
# Clean previous builds | |
rm -rf $ARCHIVE_PATH | |
rm -rf $DERIVED_DATA_PATH | |
rm -rf $XCFRAMEWORK_OUTPUT_PATH | |
# Create necessary directories | |
mkdir -p $ARCHIVE_PATH | |
# Function to log errors | |
log_error() { | |
echo "Error: $1" | |
exit 1 | |
} | |
# Function to check if directory exists | |
check_directory_exists() { | |
if [ ! -d "$1" ]; then | |
log_error "Directory $1 does not exist." | |
fi | |
} | |
# Build for iOS Devices | |
echo "Building for iOS devices..." | |
xcodebuild archive \ | |
-scheme $SCHEME \ | |
-destination="generic/platform=iOS" \ | |
-archivePath $DEVICE_ARCHIVE_PATH \ | |
-derivedDataPath $DERIVED_DATA_PATH \ | |
-sdk iphoneos \ | |
SKIP_INSTALL=NO \ | |
BUILD_LIBRARY_FOR_DISTRIBUTION=YES || log_error "Failed to build for iOS devices." | |
# Check if the device framework was created successfully | |
check_directory_exists "$DEVICE_ARCHIVE_PATH/Products/Library/Frameworks/$SCHEME.framework" | |
echo "Device framework exists: $DEVICE_ARCHIVE_PATH/Products/Library/Frameworks/$SCHEME.framework" | |
# Build for iOS Simulator with x86_64 and arm64 architectures | |
echo "Building for iOS simulator (x86_64 and arm64)..." | |
xcodebuild archive \ | |
-scheme $SCHEME \ | |
-destination="generic/platform=iOS Simulator" \ | |
-arch x86_64 \ | |
-arch arm64 \ | |
-archivePath $SIMULATOR_ARCHIVE_PATH \ | |
-derivedDataPath $DERIVED_DATA_PATH \ | |
-sdk iphonesimulator \ | |
SKIP_INSTALL=NO \ | |
BUILD_LIBRARY_FOR_DISTRIBUTION=YES || log_error "Failed to build for iOS simulator." | |
# Check if the simulator framework was created successfully | |
check_directory_exists "$SIMULATOR_ARCHIVE_PATH/Products/Library/Frameworks/$SCHEME.framework" | |
echo "Simulator framework exists: $SIMULATOR_ARCHIVE_PATH/Products/Library/Frameworks/$SCHEME.framework" | |
# Create XCFramework | |
echo "Creating XCFramework..." | |
xcodebuild -create-xcframework \ | |
-framework "$DEVICE_ARCHIVE_PATH/Products/Library/Frameworks/$SCHEME.framework" \ | |
-framework "$SIMULATOR_ARCHIVE_PATH/Products/Library/Frameworks/$SCHEME.framework" \ | |
-output $XCFRAMEWORK_OUTPUT_PATH || log_error "Failed to create XCFramework." | |
echo "XCFramework created at $XCFRAMEWORK_OUTPUT_PATH" | |
#Verifying the Frameworks | |
#To ensure the frameworks contain the correct architectures, use the lipo command: | |
lipo -info $DEVICE_ARCHIVE_PATH/Products/Library/Frameworks/$SCHEME.framework/$SCHEME | |
lipo -info $SIMULATOR_ARCHIVE_PATH/Products/Library/Frameworks/$SCHEME.framework/$SCHEME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running the Script
chmod +x build_xcframework.sh
Run the Script:
./build_xcframework.sh