Error building XCFramework with support for iOS Simulator

Hi,

I have been trying to modify the existing build script of my project (which used to build a .framework) to build .XCFramework but I am getting the below error

binaries with multiple platforms are not supported '/Users/CodeForever/Library/Developer/Xcode/DerivedData/MySDK-cjavkiibuxlwhgftpsbjmlkavwpx/Build/Products/Debug-iphonesimulator/libMySDK.a'

Not sure what am I missing here. Can someone please help me understand what could I be missing in the script or settings?

Please refer the complete script below: (running this on Xcode v15.0)

#!/bin/bash

If we're already inside this script then die

if [ -n "$RW_MULTIPLATFORM_BUILD_IN_PROGRESS" ]; then exit 0 fi export RW_MULTIPLATFORM_BUILD_IN_PROGRESS=1

RW_FRAMEWORK_NAME=${PROJECT_NAME} RW_XCFRAMEWORK_LOCATION="${BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.xcframework"

Function to build a static library for a specific platform

function build_static_library { # build_static_library sdk xcrun xcodebuild -project "${PROJECT_FILE_PATH}"
-target "${TARGET_NAME}"
-configuration "${CONFIGURATION}"
-sdk "${1}"
ONLY_ACTIVE_ARCH=NO
BUILD_DIR="${BUILD_DIR}"
OBJROOT="${OBJROOT}/DependentBuilds"
BUILD_ROOT="${BUILD_ROOT}"
SYMROOT="${SYMROOT}" $ACTION }

Build for the iOS device

build_static_library "iphoneos"

Create the iOS device XCFramework

xcodebuild -create-xcframework
-library "${BUILT_PRODUCTS_DIR}/lib${PROJECT_NAME}.a"
-output "${RW_XCFRAMEWORK_LOCATION}_iphoneos.xcframework"

Build for the iOS Simulator

build_static_library "iphonesimulator"

Create the iOS Simulator XCFramework

xcodebuild -create-xcframework
-library "${BUILT_PRODUCTS_DIR}/lib${PROJECT_NAME}.a"
-output "${RW_XCFRAMEWORK_LOCATION}_iphonesimulator.xcframework"

Merge the two XCFrameworks into a universal XCFramework

xcodebuild -create-xcframework
-framework "${RW_XCFRAMEWORK_LOCATION}_iphoneos.xcframework"
-framework "${RW_XCFRAMEWORK_LOCATION}_iphonesimulator.xcframework"
-output "$RW_XCFRAMEWORK_LOCATION"

Remove temporary XCFrameworks

rm -r "${RW_XCFRAMEWORK_LOCATION}_iphoneos.xcframework" rm -r "${RW_XCFRAMEWORK_LOCATION}_iphonesimulator.xcframework"

Copy the XCFramework to the user's desktop

cp -r "$RW_XCFRAMEWORK_LOCATION" "${HOME}/Desktop/${RW_FRAMEWORK_NAME}.xcframework"

Can someone from Apple Support team please help me out with this issue? I am blocked here as I have tried all the options found across different web searches but not none of them has resulted in being able to create xcframework which supports both iOS devices and simulators on m1 machine.

Please find the build script that I am using currently:

If we're already inside this script then stop if [ -n "$RW_MULTIPLATFORM_BUILD_IN_PROGRESS" ]; then exit 0 fi export RW_MULTIPLATFORM_BUILD_IN_PROGRESS=1

SCHEME_NAME = "Universal AESDK Framework" RW_FRAMEWORK_NAME=${PROJECT_NAME} RW_FRAMEWORK_LOCATION="${BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.xcframework" RW_ARCHIVE_LOCATION="${BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.xcarchive" RW_XCFRAMEWORK_LOCATION="${BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.xcframework"

Function to build a static library for a specific platform

function build_static_library { # build_static_library sdk if [ "${2}" == "iphonesimulator" ] && [ "${1}" == "arm64" ]; then

    xcrun xcodebuild build \
    -scheme "${TARGET_NAME}" \
    -configuration "${CONFIGURATION}" \
    -derivedDataPath "${BUILD_DIR}" \
    -arch "${1}" \
    -sdk "${2}" \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES

    mkdir -p "$BUILD_DIR/m1simulator"
    cp -r "$BUILD_DIR/Build/Products/${CONFIGURATION}-${2}/" "$BUILD_DIR/m1simulator"


else
    xcrun xcodebuild build \
    -scheme "${TARGET_NAME}" \
    -configuration "${CONFIGURATION}" \
    -derivedDataPath "${BUILD_DIR}" \
    -arch "${1}" \
    -sdk "${2}" \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES

    mkdir -p "$BUILD_DIR/${2}"
    cp -r "$BUILD_DIR/Build/Products/${CONFIGURATION}-${2}/" "$BUILD_DIR/${2}"
fi

}

#build static lib for the iOS Simulator on Intel build_static_library "x86_64" "iphonesimulator"

#build for the iOS SImulator on Mac M1 build_static_library "arm64" "iphonesimulator"

echo "before making the call to create library for iphoneos"

Build for the iOS device

build_static_library "arm64" "iphoneos"

#echo "Creating the XCFramework using individual Slices" xcodebuild -create-xcframework
-library "$BUILD_DIR/iphoneos/lib${PROJECT_NAME}.a"
-headers "$BUILD_DIR/iphoneos/include/${PROJECT_NAME}"
-library "$BUILD_DIR/m1simulator/lib${PROJECT_NAME}.a"
-headers "$BUILD_DIR/m1simulator/include/${PROJECT_NAME}"
-library "$BUILD_DIR/iphonesimulator/lib${PROJECT_NAME}.a"
-headers "$BUILD_DIR/iphonesimulator/include/${PROJECT_NAME}"
-output "$BUILD_DIR/Build/Products/${PROJECT_NAME}.xcframework"

Error building XCFramework with support for iOS Simulator
 
 
Q