microsoft / appcenter-sdk-dotnet

Development repository for the App Center SDK for .NET platforms, including Xamarin
Other
311 stars 141 forks source link

net8.0-ios projects fail to build when targeting arm64 simulators #1786

Closed rpendleton closed 2 months ago

rpendleton commented 3 months ago

Description

When using the App Center .NET SDK in a net8.0-ios project, the app fails to compile when building for simulators on an Apple Silicon Mac:

ld: in /Users/rpendleton/sd/research/AppCenterSimulator/obj/Debug/net8.0-ios/iossimulator-arm64/linker-cache/AppCenterAnalytics.a(MSACAnalytics.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/rpendleton/sd/research/AppCenterSimulator/obj/Debug/net8.0-ios/iossimulator-arm64/linker-cache/AppCenterAnalytics.a'

This is happening because the AppCenter.a file created by the binding project contains a framework with slices for an x86_64 simulator, arm64 device, and arm64e device, but it's missing a slice for arm64 simulators. Adding this slice would likely require moving from a normal .framework to an .xcframework.

Interestingly, the microsoft/appcenter-sdk-apple project already publishes an .xcframework that appears to support arm64 simulators. However, the build process for the .NET SDK strips slices from the frameworks within that .xcframework to produce a single .framework, and that framework is only compatible with the x86_64 simulator architecture.

I understand that App Center is scheduled to be retired at the end of March 2025, so I'd understand if this is something that isn't likely to be fixed. However, that's still around seven months away from now, and until we're able to fully migrate away from App Center, the lack of arm64 simulator compatibility can lead to quite a few problems.

As of Xcode 14.3, Apple no longer supports running Xcode with Rosetta. Trying to run a simulator app built for x86_64 on an arm64 Mac results in obscure defects, such as delegate events triggering multiple times unexpectedly, or swipe to delete not working in certain situations. These defects only occur when running an x86_64 simulator app on an arm64 Mac (which might seem like a defect in Xcode), but Apple's response is that defects such as these are expected, and the solution is to move away from x86_64 simulator apps on arm64 Macs.

With that said, is this something that could be fixed in a new release of the SDK? And if so, is it something your team would be willing to work on, or do you suspect that a fix would only be possible if it was contributed by an external contributor?

Repro Steps

  1. Create a new .NET iOS project using: dotnet new ios

  2. Add the following package references to the project:

    <PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.5" />
    <PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.5" />
  3. Try to build to a simulator on an Apple Silicon Mac

Details

  1. What is your app platform (Xamarin.Android or Xamarin.iOS or UWP)? net8.0-ios and net8.0-android
  2. If using Xamarin.Forms or if using portable/shared code to call our SDK APIs, are you using shared project, PCL code or .NET standard code for the application? Which .NET standard version or which PCL profile? We have some shared code, but not to call the App Center APIs. We limit the use of those APIs to the platform-specific projects.
  3. Which SDK version are you using? 5.0.5 (the latest)
  4. Which OS version did you experience the issue on? N/A, since the project doesn't compile
  5. What device version did you see this error on? arm64 simulator
  6. What third party libraries are you using? None in the sample repro steps above
  7. Please enable verbose logging for your app using AppCenter.LogLevel = LogLevel.Verbose before your call to AppCenter.Start(...) and include the logs here: N/A since the project doesn't compile
DmitriyKirakosyan commented 3 months ago

Hi @rpendleton , thank you for reaching out! This issue is a duplicate of https://github.com/microsoft/appcenter-sdk-dotnet/issues/1755, which was closed as not planned.

As a workaround, you can disable App Center in Debug mode.

You are correct about moving to xcframework. The tricky part is that the native App Center SDK is distributed as a static xcframework, which does not work well with .NET, or at least I couldn't make it work. Building a dynamic xcframework would require significant changes to the native SDK build system.

If you have the time and desire to help, we would greatly appreciate your contribution!

rpendleton commented 2 months ago

Thanks. My team had actually tried conditional PackageReferences based on RuntimeIdentifier before opening this ticket, but were running into inconsistent issues when switching back and forth between simulators and physical device. We haven't tried to make the condition based on configuration (Debug/Release) or any other property though, so I guess we'll continue down that path.

Since #1755 was closed as not planned, I'll go ahead and close this issue as not planned as well.