12

I have watched "binary framework in swift" and tried to build xcframework using xcodebuild -create-framework but it is not working properly.

I enabled "Build libraries for Distribution", then I archived and then used the command xcodebuild -create-framework -framework /path/sample.xarchive -output sample.xcframework

But it is showing an error "unable to read the file at /path/sample/sample". I am not sure what I am missing.

Sysytem Info:

MacOS: Catalina beta 1

Xcode 11

piebie
  • 2,652
  • 21
  • 30
venky
  • 1,155
  • 1
  • 11
  • 26

4 Answers4

16

Here are step by step instructions, I think you might be missing step 2:

1) Set Build Library for Distribution in the build settings for the target framework to YES

2) Again in the build settings, set Skip Install to NO otherwise the framework won't show up in the Archive output folder.

3) Archive from the Xcode Product menu after selecting your Generic iOS Device the output will appear in the Organizer. Control-Click on the Archive. Select Show in Finder Drag that to the terminal to get the path to the archive and append the path (yellow part is the dragged path, gray is navigated in subfolders). In this case it looks like this, I used the ~ to avoid showing entire path.

~/Library/Developer/Xcode/Archives/2019-06-22/Output\ 6-22-19,\ 11.50\ AM.xcarchive/Products/Library/Frameworks/MyFramework.framework

4) Then create the XCFramework by inserting the command in front of the above path:

xcodebuild -create-xcframework -output Output.xcframework -framework ~/Library/Developer/Xcode/Archives/2019-06-22/Output\ 6-22-19,\ 11.50\ AM.xcarchive/Products/Library/Frameworks/MyFramework.framework 

5) You then should see the output:

xcframework successfully written out to: ~/Project/Output.xcframework

I expect that someday soon Xcode will add a the ability to directly create the XCFramework without the command line.

possen
  • 8,596
  • 2
  • 39
  • 48
  • 3
    Mistake I made was putting the path to the .xcarchive file instead of the .framework file contained within the archive. – Peter Parker Nov 03 '19 at 00:26
  • Is it possible that `Build Libraries for Distribution` has to be set in the project settings and cannot be used as an argument for `xcodebuild`? I've seen folks mentioning to use `BUILD_LIBRARIES_FOR_DISTRIBUTION=YES` but it never works for me. I HAVE to set it in the project settings – fruitcoder Nov 22 '19 at 11:21
  • Take a note that "Build Library for Distribution" option is only available in Xcode 11. – Jayprakash Dubey Dec 13 '19 at 06:23
2

You have to do a two step process via the command line.

  1. xcodebuild archive

This will archive the framework and stick it likely in the build directory of your project.

  1. xcodebuild -create-xcframework -output FrameworkName.xcframework -framework build/Release-iphoneos/ArchivedFramework.framework

This should successfully generate the XCFramework.

cfihelp
  • 320
  • 1
  • 13
0

You typed the command wrong:

xcodebuild -create-xcframework -framework /path/sample.xarchive -output sample.xcframework
RobC
  • 22,977
  • 20
  • 73
  • 80
Ram
  • 1
0

In my case it was failing for iPhone as arm64 architecture was added in the Excluded Architecture in Build Settings

niks
  • 544
  • 11
  • 28