Try to compile for other platforms (tvOS, watchOS, visionOS, Android)
Outdated Info (both iOS and Android are supported now):
As of May 2023, NativeAOT is only (officially) supported on desktop platforms.
Regarding iOS: https://github.com/dotnet/runtime/issues/80905
Regarding Android: https://github.com/dotnet/runtime/issues/76983
Check again in .NET 8 Preview 6
As expected, this is a supported scenario in Preview 6: https://devblogs.microsoft.com/dotnet/announcing-dotnet-8-preview-6/ So we can test this now.
Unfortunately it looks like NativeAOT support for iOS in .NET 8 Preview 6 is currently limited to app projects and classlibs are not supported.
@filipnavara is that correct?
The current state of the iOS experiments is here.
Building for ios-arm64 works now with some workarounds in the csproj:
PublishAotUsingRuntimePackneeds to be set totrue(This is actually documented)_IsAppleMobileLibraryModeneeds to be set tofalse- The linker must be configured to target iOS by adding this:
<ItemGroup>
<LinkerArg Include="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk" />
<LinkerArg Include="-mios-version-min=16.0" />
</ItemGroup>
A "dummy" (unused) Main method must be present in the .NET project that's to be compiled with NativeAOT.
Many thx for your support @filipnavara!
Btw, for the Android part, that should also work if you use the Bionic RID. This issue has the latest details: https://github.com/dotnet/runtime/issues/87340. The official doc is not written up yet.
@MichalStrehovsky Many thx for the info! I'll get to Android part once I'm happy with the way things work for Apple targets.
https://github.com/dotnet/runtime/pull/93658 will add proper iOS library support to .NET. Once that lands, we should remove the various workarounds that are in place today.
There's hope for visionOS support: https://github.com/dotnet/runtime/issues/87929