skip to Main Content

If you create new project from Xcode (v16) and choose framework, and then build it, it results in a .framework.
How do you instead get it to build an .xcframework?
When creating the framework project there’s no options presented to create one or the other.

2

Answers


  1. An xcframework is an archive of frameworks with different architectures. You should create the framework first and then create the xcframework. An xcframework is somewhat like a fat framework.
    First, create frameworks for each architecture. Then, create the xcframework by:

        xcodebuild -create-xcframework 
        -framework yourAppSimulator.framework 
        -framework yourAppIOS.framework 
        -output yourApp.xcframework
    
    
    Login or Signup to reply.
  2. To create an .xcframework instead of a .framework in Xcode, follow these steps:

    1. ”Create a New Xcode Project or Use Existing Framework Project”
      Open Xcode and either create a new project or use an existing project containing the .framework you want to convert to an .xcframework.

    2. ”Build the Framework for Different Architectures/Platforms”
      .xcframework allows you to package multiple frameworks for different platforms (e.g., iOS, macOS, etc.) and architectures (e.g., arm64, x86_64). You need to build the framework for these different combinations.

      In your Xcode project, set the build target to include the platforms and architectures you want the .xcframework to support.

    3. ”Archive the Framework for Each Platform and Architecture”
      For each platform you want to support (e.g., iOS, macOS, etc.), follow these steps:

      1. In the ”Xcode menu”, go to ”Product > Archive”.
      2. Select the desired target platform from the device/target dropdown in Xcode.
      3. Click ”Archive” to build and archive the framework for that platform/architecture.

      You need to archive your framework for every target architecture (e.g., arm64, x86_64) and platform (e.g., iOS, macOS).

    4. ”Create the .xcframework
      Once you have all the archives for the different platforms/architectures, you can create an .xcframework by following these steps:

      1. Open Xcode.
      2. In the Xcode menu, go to File > New > Archive.
      3. In the Organizer window, select the Distribute Contentoption for the archived framework.
      4. Select Export as ‘XCFramework’ from the options.

      This will create the .xcframework that includes the frameworks for all the platforms and architectures you’ve built.

    5. Verify the .xcframework
      Once the .xcframework is created, verify that it contains the correct framework for each target platform and architecture. You can inspect it using the terminal:

      lipo info YourFramework.xcframework/iosarm64/YourFramework.framework/YourFramework
      

      This will show the architectures included in the framework.

    6. Distribute the .xcframework
      After successfully creating the .xcframework, you can distribute it by sharing the .xcframework file. This can be added to projects via CocoaPods, Carthage, or directly integrated into your own project.

    Alternative: Using the Command Line
    If you prefer using the command line, you can use xcodebuild to build the framework and then use xcodebuild createxcframework to package it as an .xcframework:

    xcodebuild createxcframework 
      framework path/to/iosarm64/YourFramework.framework 
      framework path/to/iosx86_64/YourFramework.framework 
      output path/to/output/YourFramework.xcframework
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search