.NET for Android 錯誤/警告 XA1023

範例訊息

error XA1023: Using the DX DEX Compiler is not supported. Please set the DEX compiler to 'd8' in the Visual Studio project property pages or edit the project file in a text editor and set the 'AndroidDexTool' MSBuild property to 'd8'.
warning XA1023: Using the DX DEX Compiler is deprecated. Please set the DEX compiler to 'd8' in the Visual Studio project property pages or edit the project file in a text editor and set the 'AndroidDexTool' MSBuild property to 'd8'.
error XA1023: Using the DX DEX Compiler is not supported in .NET for Android projects that target .NET 6 or higher. Please set the DEX compiler to 'd8' in the Visual Studio project property pages or edit the project file in a text editor and set the 'AndroidDexTool' MSBuild property to 'd8'.

問題

Google 已棄用 DX DEX 編譯器,改用 D8 DEX 編譯器。 自 2021 年 2 月 1 日起,DX 將不再是 Android SDK 或 Android Studio 的一部分。

DX DEX 編譯器將不支援 .NET 6 及以上版本,也不支援 .NET for Android 12.4 及以上版本。

解決方法

更新 $(AndroidDexTool) MSBuild 屬性,來選擇 d8 D8 DEX 編譯器。 此屬性對應於 Visual Studio 專案屬性頁面中的 Dex 編譯器 設定。 或者,從 <AndroidDexTool> 檔案中移除 ,讓組建選取預設值 d8。