Cocoapods: Add support for the new xcframework format introduced in Xcode 11

Created on 6 Sep 2019  路  28Comments  路  Source: CocoaPods/CocoaPods

Apple introduced a new .xcframework bundle format for both ObjC and Swift/mixed frameworks. The main benefit is that this structure can contain multiple architectures and doesn't require lipo to fuse them together.

Here's how the structure looks like:

Screenshot 2019-09-06 at 19 29 29

An xcframework can be made by xcodebuild -create-xcframework which takes -framework and -output options. xcframework supports both source and binary frameworks. dSYM still need to be manually added, just like you had to with binary frameworks.

Learn more:

Somewhat related Issues might be

Hot take: Apple was forced to innovate here after years of both communicating that one definitely shouldn't use lipo, yet not offering a different solution. Now Mac Catalyst is here with the same hardware architecture as macOS, but different enough that it requires a separate app architecture "iosmac" and thus a separate binary.

What we need:

moderate enhancement

Most helpful comment

I'll be working on this soon 馃帀

All 28 comments

PSPDFKit is willing to sponsor part of development. Maybe another company joins our efforts? Hit me up on Twitter for details.

SG! lets do it for 1.9.0. Marked it as enhancement.

We also have an RFC template for anyone who wants to use.

Stripping architectures is no longer necessary

This should only apply to the xcframework, right ? The new changes should not effect all current spec.vendored_framework behavior.

To vendor a precreated binary xcframework framework, we could very well re-use spec.vendored_framework and just point to the xcframework folder instead. Logic-wise it should be easy to differentiate between the old and new format and then do the right thing (like not stripping xcframework)

@steipete remember that xcframeworks can contain both static and dynamic libraries thus I wouldn't use vendored_framework since they are always dynamic (I think)
I already implemented support for .frameworks inside the XCFramework:
image
You can see my work on Core and CocoaPods, of course this is experimental and will only work with dynamic frameworks
Also there are 0 tests here, probably many things are broken

Static libraries are a bit more complex because there is no script to link against them

Since static libraries don't get the same module stability support in xcframework bundle - from the creation + integration point as discussed here, open radar here,
could the support for the static libraries be delivered in different round?

I could add an error for Static XCFrameworks.
Let me try doing that

@Itaybre vendored_frameworks can already contain static frameworks, and often do. Cocoapods automatically inspects the framework to determine if it's a static or dynamic binary then handles appropriately. (See file_accessor.rb)

(Similarly, vendored_libraries can also be either static or dynamic, and it's doing similar handling for those)

any news?

No news so far. Issue is open and people are welcome to contribute here!

I'll be working on this soon 馃帀

Any updates? :)

Yes! I've gotten most of this working, with some edge cases to be handled.

There's a possibility we won't be able to support every platform/arch combination using scripts, so we might have to resort to using native Xcode build phases. I'll have more updates soon!

I'm used to shipping some internal pods with a vendored framework and associated .dSYM, utilizing the automatic copying added in https://github.com/CocoaPods/CocoaPods/pull/6536. Will there be anything similar for xcframework distribution with CocoaPods?

Yes, I haven't decided quite yet how that will work but we may do something similar of the existing workflow, such as looking for a folder with the same name but appending .dSYMs. We are trying to avoid introducing changes to the DSL if possible

Hi
Is anyone able to integrate the xcframework using cocoapods? Please let me know if anyone has resolved this issue as i am stuck with it and have been providing the library manually.

@NishantTiwarins we have an open Pull Request as mentioned above, but it's not merged yet.

@amorde Hi Eric! Do you know by when it will be merged and deployed? An ETA would be really helpful. Thank you!

Don't have a specific timeline for you unfortunately, but I can say we are planning to release a beta soon after it gets merged so people can start testing it!

@amorde Thanks Eric! I look forward.

Hi, I've just tested it in beta and it seems not to be working correctly for my specific case. In my app I have also subproject with framework that has dependency on other framework (xcframework) distributed through CocoaPods and in this subproject it it always trying to link with iOS version even xcframework contains also Simulator and MacCatalyst version of framework.

ld: warning: ignoring file /<<path>>/<<framework name>>.xcframework/ios-arm64/<<framework name>>.framework/<<framework name>>, building for Mac Catalyst-x86_64 but attempting to link with file built for iOS-arm64
Undefined symbols for architecture x86_64

I see that [CP] Prepare Artifacts is injected to main app Build Phases.
Anything what I can try to make it working?

UPDATE:
Seems when linking my subproject it is trying to link with all three versions of framework distributed through CocoaPods inside xcgramework bundle.

-F/<<path to Pods>>/Pods/<<framework folder>>/<<framework name>>.xcframework/ios-arm64 -F/<<path to Pods>>/Pods/<<framework folder>>/<<framework name>>.xcframework/ios-x86_64-maccatalyst -F/<<path to Pods>>/Pods/<<framework folder>>/<<framework name>>.xcframework/ios-x86_64-simulator

use XCFrameworkBuild

A script program that helps you build XCFramework quickly, and supports conversion of .framework and .a before .xcframework.

Hi

I am using the cocoapods version 1.9.0.beta.2

I am trying to distribute my xcframework through the podspec file

My podspec file contains this

spec.name = 'SDKNAME'
spec.version = 'VERSION NUMBER'
spec.license = {:type => 'MIT', :file => 'License.md'}
spec.homepage = 'URL OF THE PRODUCT'
spec.authors = { 'AUTHOR NAME' => 'AUTHOR EMAIL'}
spec.summary = 'SUMMARY OF THE SDK'
spec.source = { :git => "GIT URL OF THE SDK", :tag => 'VERSION OF THE SDK'}
spec.source_files = 'SDK.xcframework/Headers/*.{h,m,swift}'
spec.library = 'z', 'sqlite3', 'xml2.2'
spec.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(SDKROOT)/usr/include/libxml2' }
spec.vendored_frameworks = 'SDK.xcframework','Vendors/VENDORSDK1.xcframework','Vendors/VENDORSDK2.framework'
spec.documentation_url = 'Documetation URL'
spec.framework = 'FRAMEWORK NAME'
spec.exclude_files = "Classes/Exclude"
spec.platform = :ios, "10.0"
end

Here vendor1 and vendor 2 is my dependencies framework. Out of which i have vendor1 as a XCframework. I get the following error - ERROR | [iOS] file patterns: The source_files pattern did not match any file.

What i am doing wrong? can anyone please help me with this .

Hi

I am using the cocoapods version 1.9.0.beta.2

I am trying to distribute my xcframework through the podspec file

My podspec file contains this

spec.name = 'SDKNAME'
spec.version = 'VERSION NUMBER'
spec.license = {:type => 'MIT', :file => 'License.md'}
spec.homepage = 'URL OF THE PRODUCT'
spec.authors = { 'AUTHOR NAME' => 'AUTHOR EMAIL'}
spec.summary = 'SUMMARY OF THE SDK'
spec.source = { :git => "GIT URL OF THE SDK", :tag => 'VERSION OF THE SDK'}
spec.source_files = 'SDK.xcframework/Headers/*.{h,m,swift}'
spec.library = 'z', 'sqlite3', 'xml2.2'
spec.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(SDKROOT)/usr/include/libxml2' }
spec.vendored_frameworks = 'SDK.xcframework','Vendors/VENDORSDK1.xcframework','Vendors/VENDORSDK2.framework'
spec.documentation_url = 'Documetation URL'
spec.framework = 'FRAMEWORK NAME'
spec.exclude_files = "Classes/Exclude"
spec.platform = :ios, "10.0"
end

Here vendor1 and vendor 2 is my dependencies framework. Out of which i have vendor1 as a XCframework. I get the following error - ERROR | [iOS] file patterns: The source_files pattern did not match any file.

What i am doing wrong? can anyone please help me with this .

Try updating your pattern to:
spec.source_files = 'SDK.xcframework/*/SDK.xcframework/Headers/*.{h,m,swift}'

Hi, I've just tested it in beta and it seems not to be working correctly for my specific case. In my app I have also subproject with framework that has dependency on other framework (xcframework) distributed through CocoaPods and in this subproject it it always trying to link with iOS version even xcframework contains also Simulator and MacCatalyst version of framework.

ld: warning: ignoring file /<<path>>/<<framework name>>.xcframework/ios-arm64/<<framework name>>.framework/<<framework name>>, building for Mac Catalyst-x86_64 but attempting to link with file built for iOS-arm64
Undefined symbols for architecture x86_64

I see that [CP] Prepare Artifacts is injected to main app Build Phases.
Anything what I can try to make it working?

UPDATE:
Seems when linking my subproject it is trying to link with all three versions of framework distributed through CocoaPods inside xcgramework bundle.

-F/<<path to Pods>>/Pods/<<framework folder>>/<<framework name>>.xcframework/ios-arm64 -F/<<path to Pods>>/Pods/<<framework folder>>/<<framework name>>.xcframework/ios-x86_64-maccatalyst -F/<<path to Pods>>/Pods/<<framework folder>>/<<framework name>>.xcframework/ios-x86_64-simulator

Hi @BalkiX , got any resolution to that issue?
I have exactly the same situation.

@merocode-com mind submitting another issue with a sample project?

If anyone is experiencing issues with XCFramework support new issues would be greatly appreciated. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

soleares picture soleares  路  3Comments

marzapower picture marzapower  路  3Comments

pronebird picture pronebird  路  3Comments

dawnnnnn picture dawnnnnn  路  3Comments

evermeer picture evermeer  路  3Comments