.NET for Android 警告 XA1040

示例消息

warning XA1040: The NativeAOT runtime on Android is an experimental feature and not yet suitable for production use. File issues at: https://github.com/dotnet/android/issues

問题

NativeAOT 是适用于 Android 的 .NET 的实验性运行时选项。 当你在受支持的发布或优化构建中通过 $(PublishAot)=true 启用 NativeAOT 时,系统会发出此警告,表明 NativeAOT 尚不适合在生产环境中使用。

支持的运行时包括:

  • CoreCLR (.NET 11 及更高版本中 Android 应用程序的默认值)
  • MonoVM 是 .NET 10 及更早版本的默认选项,并且仅在受支持的目标上通过 $(UseMonoRuntime)=true 提供。
  • NativeAOT,在受支持的发布或优化构建中由 $(PublishAot)=true 选择

在 .NET 11 及更高版本中,$(UseMonoRuntime)=true 会因 NETSDK1242 而被拒绝;它不是绕过 CoreCLR 的途径。

解决方案

若要静音此警告,可以:

  • 从项目文件中移除 $(PublishAot)=true 以使用受支持的运行时。

  • 将 $(EnablePreviewFeatures) 设置为 true 以在项目文件中确认 NativeAOT 的实验性质。