Closed
Description
xcframework are a new format of frameworks which allow multiple platforms to live side by side.
We should teach binding projects (XI and XM) to accept xcframework bundles.
In addition, we need to research how we can leverage this:
- Packaging some of our libraries our outputs?
- Embeddinator output (if so, file issue with details and move on)
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
[-][xcode11-feature] xcframework support[/-][+][xcode11-support] xcframework support[/+]awattar commentedon Sep 1, 2020
Hi. Any ETA for this enhancement?
chamons commentedon Sep 2, 2020
Thanks for the interest @awattar - In general we don't have ETA for enhancements. Either they are in work or our backlog.
Right now the teams is focused on Xcode 12 and the port to .NET 6, so it may be some time before we pick this up.
awattar commentedon Sep 2, 2020
Thanks @chamons. It started to be a problem because apps referencing dynamic frameworks cannot be distributed to AppStore due to unsupported architecture - x86_64 so most of them were switched to modern xcframeworks that are currently unsupported by the Xamarin.iOS bindings/apps. Workarounds require special IPA handling or creating cumbersome configurations for simulator/device.
It is not something new but over a year old enhancement that could be put somewhere in the schedule for the sake of loyal developers and their customers ;)
nrbrook commentedon Sep 2, 2020
@awattar @chamons It is possible to strip non-iOS architectures out of dynamic frameworks during build using a script such as Realm's for submitting to App Store. For frameworks that have switched to XCFramework, the relevant frameworks could be pulled out of the XCFramework and merged as required.
However, another problem is approaching with Apple Silicon. Xcode 12 builds simulator binaries for x86_64, i386, and now arm64 by default, for running in simulator on Apple Silicon. If attempting to make a fat binary, the arm64 simulator slice conflicts with the iOS arm64 slice. The arm64 simulator slice can be removed with lipo, but this means that the framework can't run in simulator on Apple Silicon. As such, I have to distribute a fat binary which doesn't support Apple Silicon for Xamarin. This means that until XCFrameworks are supported, many Xamarin projects using binary libraries and frameworks will not run in the simulator on Apple Silicon.
rolfbjarne commentedon Sep 7, 2020
@nrbrook that's a very good point, and we'll have it in mind when we're adding simulator support on Apple Silicon
tonyarnold commentedon Nov 6, 2020
We've just hit this with Reveal's SDK - we're in a tight spot here: we can't really afford not to support Apple Silicon in our framework, but this necessitates shipping as an XCFramework so that there's no overlapping slices.
Is there an ETA on support for Xamarin consuming XCFrameworks?
chamons commentedon Nov 6, 2020
It's in work - #10046
15 remaining items
spouliot commentedon Mar 2, 2021
This is basically what we're doing. The msbuild task is resolving the correct
.framework
path inside the.xcframework
based on the OS and architecture. The rest of the build (e.g.mtouch
and native compiler/linker) are unaware of XCFrameworks.spouliot commentedon Mar 2, 2021
Closing: d16-9 (XI 14.14) was released to stable
4brunu commentedon Mar 2, 2021
Does this means that now Xamarin fully supports XCFrameworks?
leonluc-dev commentedon Mar 3, 2021
There are still a few issues with this it seems.
On Visual Studio for Mac (using Xamarin.iOS 14.14.2.5) I can build a binding project with a xcframework native reference fine and judging by the resulting DLL size and content the xcframework is included within it.
However when I use said DLL (or direct project reference) in a Xamarin.iOS app an issue occurs.
While the C# classes part of the binding are available it seems the framework (derived from the embedded xcframework) is not included in the app build, even though it is included in the dll. This leads to the same MT5211 errors mentioned earlier.
The only way I can make the binding project/dll work is explicitly include the xcframework in the Xamarin.iOS app itself as a native reference.
For binding projects with references to static libraries (.a) or non-xc frameworks it still works as expected (.a and .framework embedded in the binding are included in the build).
I've added a test project showing this issue (using the Universal framework that was supplied as a test xcframework):
BindingTest.zip
4brunu commentedon Mar 3, 2021
Is there any issue where we I can follow this problem?
leonluc-dev commentedon Mar 3, 2021
I've created a new issue for the binding project issue specifically: #10774
leonluc-dev commentedon Mar 4, 2021
There is also a Windows exclusive bug regarding xcframeworks.
Whenever a Xamarin.iOS app references a xcframework (and builds fine on mac) the build process produced the following error on Windows (connected to a Mac build server):
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Xamarin\iOS\Xamarin.Shared.targets(142,3): error : Universal.xcframework has an incorrect or unknown format and cannot be processed.
Building a binding project on Windows doesn't generate the above error, but the resulting DLL is missing the expected embedded xcframework. This also doesn't happen on Mac.
The above error seems to be error E0174 which can only be found in the code block below, but I haven't been able to figure out why it happens/why it only happens on Windows builds.
https://github.com/xamarin/xamarin-macios/blob/5ef69f173bcab367117f031bc4faa48dfec3e42c/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/ResolveFrameworksBase.cs#L149-L163
nguyenhuutinh commentedon Apr 23, 2021
@leonluc-dev : do you have any update?
Does Xamarin fully supports XCFrameworks now?
I tried to create our sdk for Xamarin but it seems hard for us to understand how to create binding project with XCFrameworks.
All tutorial documents are also not updated for XCFramework.
leonluc-dev commentedon Apr 23, 2021
@nguyenhuutinh I don't know the exact details (I'm not part of the Xamarin team). But Xamarin does support XCFrameworks on Mac, although with a few quirks to keep in mind. On Windows it's still broken (as of April 23, 2021 using Visual Studio 16.9.4).
Windows
Any Xamarin.iOS apps referencing a XCframework based binding projects will not build on Windows (the compiler will show linker errors)(This was fixed in Visual Studio 16.10)Mac
On Mac using XCFrameworks in Xamarin binding projects works, but there are a few things to keep in mind:
You add the XCFramework to the binding project as a native reference just like you would a regular framework or static library.
There is currently a bug in Visual Studio for Mac which causes any XCFramework native reference to be marked as a static library after they are added to the project. You need to manually change this flag back to Framework.
NoBindingEmbedding
value to be set on the project file. As of now, Visual Studio for Mac doesn't do this for you, so you have to set this value manually.ApiDefinition.cs and Structs.cs files are written the same way as with static libraries and regular frameworks
After building the binding project the output folder will contain a dll file and a .resources folder. You need both the dll file and the resources folder to use the binding in a Xamarin.iOS app.
If you add the binding to a Xamarin.iOS app as a project reference the .resources folder will be handled automatically.
If you reference the resulting dll directly make sure the .resources folder is in the same location as the dll for it to work (you don't need to explictly reference the .resources folder. It being in the same folder as the dll is enough.)
NOTE: As for now Objective Sharpie, a tool to automatically generate ApiDefinition.cs files, cannot handle XCFrameworks yet. So you have to write the definition files manually or generate the files from a regular framework version of the library you want to bind and reuse them were possible.
Hopefully most of the bugs on Windows and in Visual Studio for Mac get ironed out soon. But this should at least get you a working XCFramework binding on Mac.
nguyenhuutinh commentedon Apr 23, 2021
@leonluc-dev thanks for your detail information.
Yes, I got problem when using Objective Sharpie to generate metadata from XCFramework.
let me try to do it manually.
Thank you
nguyenhuutinh commentedon Apr 26, 2021
hi @leonluc-dev , thanks, I tried with your suggestion. I can compile now.
But I got this error due to new instance of my class in framework.
var test = new CoverService();
inViewDidLoad()
seems that Xamarin didnot load my xcframework correctly.
have you experienced on this or any suggestion how to debug this issue?
Thanks
leonluc-dev commentedon Apr 26, 2021
@nguyenhuutinh I'm not sure. The most common causes I've seen for that error are:
In a lot of these cases the binding project might still compile but will give runtime errors when used in an app.
nguyenhuutinh commentedon Apr 26, 2021
ok thank you.
I used this command to generate binding files:
sharpie bind -framework ./CoverSDK.xcframework/ios-arm64_armv7/CoverSDK.framework --namespace CoverSDK