How to create FAT / Universal framework with XCode 13?

2.3k Views Asked by At

We were using a script to create a FAT framework before where we followed the below steps.

  • create a framework for iOS devices
  • create a framework for simulator devices
  • merge the above two frameworks & it will be your FAT / Universal framework.

The same script is not working fine after XCODE 12.4 so it seems that there is some change that is specific to XCODE 13+.

Can anyone please guide the steps to create FAT / Universal Framework with XCODE 13?

1

There are 1 best solutions below

1
Tolga İskender On

try this one "Build Phase" -> click "+" icon -> "New Run Script Phase" copy below code there and build with simulator and Any iOS Device.Your fat framework will be in your project folder

#1. After then make a fresh directory directory 

UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal

# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"


# 2. Copy Device(arm64) Framework at fresh universal folder location 
cp -a "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"



#3. Copy Sim(x86_64) Frameworks's "MyFramework.swiftmodule" Folder Content & paste it at  Fat(x86_64 + arm64) Frameworks's  "MyFramework.swiftmodule" folder.

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. Copy output at Project Directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"

# Step 6. Open Project Directory
open "${PROJECT_DIR}"#1. After then make a fresh directory directory 

UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal

# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"


# 2. Copy Device(arm64) Framework at fresh universal folder location 
cp -a "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"



#3. Copy Sim(x86_64) Frameworks's "MyFramework.swiftmodule" Folder Content & paste it at  Fat(x86_64 + arm64) Frameworks's  "MyFramework.swiftmodule" folder.

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. Copy output at Project Directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"

# Step 6. Open Project Directory
open "${PROJECT_DIR}"