Android 版 .NET 警告 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

Issue

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 的實驗性質。