Skip to main content

How To Create XCFramework?

·1 min
Table of Contents

XCFramework is a single package created by xcode which contains binary framework/library for multiple platforms (iOS, macOS, tvOS, watchOS, Simulator).

We will create the XCFramework in two steps

Step 1 #

Create framework or library archive for each platform.

for iOS Device

xcodebuild archive \
    -project MyFramework.xcodeproj \
    -scheme MyFramework \
    -destination "generic/platform=iOS" \
    -archivePath "archives/MyFramework-iOS" \
    SKIP_INSTALL=NO \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES

for iOS Simulator

xcodebuild archive \
    -project MyFramework.xcodeproj \
    -scheme MyFramework \
    -destination "generic/platform=iOS Simulator" \
    -archivePath "archives/MyFramework-iOS_Simulator" \
    SKIP_INSTALL=NO \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES

By changing the destination flag, you can build for any platform. Replace MyFramework with actual framework name. BUILD_LIBRARY_FOR_DISTRIBUTION build setting is set to Yes to enable support for library evolution and generation of a module interface file. SKIP_INSTALL build setting is set to No so the built products included in the archives.

Step 2 #

Combine framework archives into XCFramework

xcodebuild -create-xcframework \
    -archive archives/MyFramework-iOS.xcarchive -framework MyFramework.framework \
    -archive archives/MyFramework-iOS_Simulator.xcarchive -framework MyFramework.framework \
    -archive archives/MyFramework-macOS.xcarchive -framework MyFramework.framework \
    -archive archives/MyFramework-Mac_Catalyst.xcarchive -framework MyFramework.framework \
    -output output/MyFramework.xcframework