inikityuk / Xamarin.MaterialComponents.iOS.NET

Port of Xamarin.iOS.MaterialComponents to NET 7
Other
0 stars 0 forks source link

NuGet package bundles xcframeworks without arm64 simulator support #1

Open sasha-borodin opened 2 months ago

sasha-borodin commented 2 months ago

First, thank you for your hard work on making this binding available!

The issue is the following compilation error when this NuGet package is referenced from a project whose TargetFramework is net8.0-ios:

3>Xamarin.Shared.targets(146,3): Error : No matching framework found inside '/Users/alexander/.nuget/packages/xamarin.materialcomponents.ios.net/1.0.0/lib/net7.0-ios16.1/MaterialComponents.iOS.NET.resources/MDFInternationalization.xcframework'. SupportedPlatform: '/Users/alexander/.nuget/packages/xamarin.materialcomponents.ios.net/1.0.0/lib/net7.0-ios16.1/MaterialComponents.iOS.NET.resources/MDFInternationalization.xcframework', SupportedPlatformVariant: 'ios', SupportedArchitectures: 'simulator'.

From externals/MDFInternationalization.xcframework/Info.plist:

        <dict>
            <key>LibraryIdentifier</key>
            <string>ios-x86_64-simulator</string>
            <key>LibraryPath</key>
            <string>MDFInternationalization.framework</string>
            <key>SupportedArchitectures</key>
            <array>
                <string>x86_64</string>
            </array>
            <key>SupportedPlatform</key>
            <string>ios</string>
            <key>SupportedPlatformVariant</key>
            <string>simulator</string>
        </dict>

Note that SupportedArchitectures does not include arm64. This is confirmed by running lipo -i on externals/MDFInternationalization.xcframework/ios-x86_64-simulator/MDFInternationalization.framework/MDFInternationalization.

Is this anything that has been reported or considered? If not, I'm happy to fork and make an attempt at bindling xcframeworks with arm64 simulator support. However, any guidance you can offer (such as your approach to obtaining the current xcframeworks) would be much appreciated.

Thank you again.

inikityuk commented 2 months ago

Hi @sasha-borodin ,

I originally created this binding project to help myself and others to migrate Xamarin.iOS projects to NET7.

The way I made it : (very high level steps)

  1. pulled https://github.com/xamarin/XamarinComponents and resolved "cake" issues (not fun)
  2. run 'dotnet cake --target=externals' to download xcframeworks (read repo documentation)
  3. build 'MaterialComponents' using 'cake' or directly from xcode (as soon as you get "externals" downloaded you will get you way up), you might need to adjust 'cake' script to make it work and build your configuration (i.e. arm64)
  4. use 'lipo' to combine 'x86_64' and 'arm64' frameworks into one xcframework
  5. replace/add xcframeworks in Binding NET project and build
  6. Create proper Nuget package

Keep in mind each of this steps will create new set of issues for you to resolve, be ready if you choose to go this way.

The most proper way is just to build source code from xcode with required architecture and get required xcframeworks. However it is a very time consuming way and you will get all possible issues to have fun with, including fixing original source code as it might been built with older xcode versions.

I'm going to migrate the same app to NET8 within next 4-6 months and if I can't get rid of this package in my app, I will have to update nuget to support NET8. (can't promise anything)

I would try to get rid of 'XamarinComponents' from the app as it will make it harder and harder to maintain.

The original purpose of this library was to make migration to NET7 much easier and not to support life of this dead (but still working in production) library.

Regards, Igor

inikityuk commented 2 months ago

@sasha-borodin could you check your: "externals/MDFInternationalization.xcframework/ios-x86_64-simulator/MDFInternationalization.framework/MDFInternationalization" location should also have "externals/MDFInternationalization.xcframework/ios-arm64/MDFInternationalization.framework"

Just like on my screenshot: 2024-05-03_22-39

sasha-borodin commented 2 months ago

Thanks for the quick response @inikityuk!

I checked the contents of MDFInternationalization.xcframework folder under my project's bin/Debug/net8.0-ios/iossimulator-arm64/MaterialComponents.iOS.NET.resources folder, and there is an ios-arm64 framework as well as an ios-x86_64-simulator framework (just like in your screenshot), but not a "fat" ios-arm64_x86_64-simulator framework (as expected).

I would also like to remove my project's dependency on the MaterialComponents library. But that is a big undertaking, and will have to wait until later. In the meantime, I will try to fork your repository, build or obtain new versions of the external xcframeworks (per your instructions above), and see how far I get :-)

Thanks again for your help.

inikityuk commented 2 weeks ago

Hey @sasha-borodin,

I just upgraded one of my projects from NET7 to NET8 and was able to use this package with no changes at all, for both devices and simulators.

if you download/install this package from nuget into existing NET8 project -> you should be just fine. https://www.nuget.org/packages/Xamarin.MaterialComponents.iOS.NET

The only difference I can see is: I'm building project on M2 Mac, you might be building on Intel Mac.

This section of release NET8 notes might help: https://github.com/xamarin/xamarin-macios/wiki/.NET-8-release-notes#default-runtimeidentifiers

Regards, Igor

sasha-borodin commented 2 weeks ago

@inikityuk - are you using the ForceSimulatorX64ArchitectureInIDE project setting? What IDE are you using to perform the build? In theory, this project setting should force the build process to target iossimulator-x64, even when building on an ARM Mac. This should remove the requirement for ARM simulator support.

However, I'm using the Rider IDE, and the setting seems to have no effect.

Just in case this helps anyone else using your library, Microsoft has offered a solution here: https://github.com/xamarin/xamarin-macios/issues/20712#issuecomment-2162384851

And I've filed a support request with JetBrains to troubleshoot support for this setting in Rider here: https://youtrack.jetbrains.com/issue/RIDER-113336/Support-for-ForceSimulatorX64ArchitectureInIDE-iOS-project-setting