xcframework does not contain internal frameworks

Like https://forums.developer.apple.com/message/389765#389765, I am trying to create an xcframework file for a few third party libraries I'm using. Following the instructions from https://appspector.com/blog/xcframeworks, I



1. Create platform-specific framework files:

# Archive for device
xcodebuild archive -scheme TestFramework -destination="iOS" -archivePath /tmp/xcf/ios.xcarchive -derivedDataPath /tmp/iphoneos -sdk iphoneos SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES


# Archive for simulator
xcodebuild archive -scheme TestFramework -destination="iOS Simulator" -archivePath /tmp/xcf/iossimulator.xcarchive -derivedDataPath /tmp/iphoneos -sdk iphonesimulator SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES


At this point, I've gotten two frameworks with swiftmodule files; everything looks good. The frameworks do *not* come with swiftinterface

files, but I think that is alright as these are objc projects. Then, I



2. Combine the individual frameworks to form a single xcframework file:

# Build xcframework with two archives
xcodebuild -create-xcframework -framework /tmp/xcf/ios.xcarchive/Products/Library/Frameworks/TestFramework.framework -framework /tmp/xcf/iossimulator.xcarchive/Products/Library/Frameworks/TestFramework.framework -output /tmp/xcf/TestFramework.xcframework


Here, xcodebuild doesn't fail, but it emits a curious error:

No 'swiftinterface' files found within '/Users/user/git/ReactiveObjC/output/xcf/ios.xcarchive/Products/Products/Library/TestFramework.framework/Modules/TestFramework.swiftmodule'.


Crucially, the xcframework package does not contain the individual frameworks or folders specified in the Info.plist file. Obviously, when I try to link to the xcframework in this state, I get a bunch of "missing symbols" linker errors.



Why is this? What must I do to get xcodebuild to create the xcframework completely?



NB: Manually creating the folders seems to work for now, but this feels wrong and is brittle – Apple can change the way xcodebuild works anytime.

Accepted Reply

Turns out that adding BUILD_LIBRARY_FOR_DISTRIBUTION = YES to the end of the xcodebuild command was not enough / not working to produce a framework with the required swiftinterface files. I had to go in the settings for the actual project and manually set BUILD_LIBRARY_FOR_DISTRIBUTION to YES, like this answer suggests, then I was able to get frameworks with the swiftinterface files. After I got the frameworks with the swiftinterface files, I was then able to create the xcframework file using xcodebuild without any problems.

  • I work this solution; I opened the xcode and I searched BUILD_LIBRARY_FOR_DISTRIBUTION in Buid setings and changed to "YES" I deleted platform-specific and rebiuld again

Add a Comment

Replies

Turns out that adding BUILD_LIBRARY_FOR_DISTRIBUTION = YES to the end of the xcodebuild command was not enough / not working to produce a framework with the required swiftinterface files. I had to go in the settings for the actual project and manually set BUILD_LIBRARY_FOR_DISTRIBUTION to YES, like this answer suggests, then I was able to get frameworks with the swiftinterface files. After I got the frameworks with the swiftinterface files, I was then able to create the xcframework file using xcodebuild without any problems.

  • I work this solution; I opened the xcode and I searched BUILD_LIBRARY_FOR_DISTRIBUTION in Buid setings and changed to "YES" I deleted platform-specific and rebiuld again

Add a Comment
The setting is BUILD_LIBRARY_FOR_DISTRIBUTION. Singular not plural. I was running into this as well and just coded it up.

Hi, I have a static library with cocoa-pods e.g. Alamofire. When the library is built, respective Alamofire.framework is generated in Debug-iphoneos and Debug-iphonesimulator folders. I am trying to generate xcframework from those two using xcodebuild -create-xcframework. However just Info.plist is added in the Alamofire.xcframework folder. The _CodeSignature folder in Alamofire.framework for Debug-iphoneos is missing and I doubt this is the reason for not having ios-arm64 and ios-x86_64-simulator with respective .framework in the xcframework

If I create my own framework and generate xcframework e.g TestFramework.xcframework does have Info.plist, ios-arm64 and ios-x86_64-simulator with respective TestFramework.framework

I would be grateful if someone helps me understanding and resolving the issue.

Thanks & Regards

Alternatively

If you're doing this operation often, or if you wanted to automate (CI/CD) this process you can also use the CLI tool Surmagic https://github.com/gurhub/surmagic.

As mentioned earlier, you made a typo

# Archive for device
xcodebuild archive -scheme TestFramework -destination="iOS" -archivePath /tmp/xcf/ios.xcarchive -derivedDataPath /tmp/iphoneos -sdk iphoneos SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES


# Archive for simulator
xcodebuild archive -scheme TestFramework -destination="iOS Simulator" -archivePath /tmp/xcf/iossimulator.xcarchive -derivedDataPath /tmp/iphoneos -sdk iphonesimulator SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

You should use BUILD_LIBRARY_FOR_DISTRIBUTION instead of BUILD_LIBRARIES_FOR_DISTRIBUTION.

Library Evolution in Swift

https://xcodebuildsettings.com/#build_library_for_distribution