.NET for Android 錯誤 XA1011

範例訊息

error XA1011: Using ProGuard with the D8 DEX compiler is no longer supported. Please set the code shrinker to 'r8' in the Visual Studio project property pages or edit the project file in a text editor and set the 'AndroidLinkTool' MSBuild property to 'r8'.

Issue

專案目前配置為結合 D8 DEX 編譯器與 ProGuard 程式碼縮減器。 過去允許在 D8 DEX 編譯器中使用 ProGuard 的代碼縮減器,但現在僅支援 R8 的代碼縮減器用於 D8 DEX 編譯器。

解決方案

在 Visual Studio 專案屬性頁面中將 程式碼縮 減器設為 r8,或 在 Visual Studio 或其他文字編輯器中編輯專案檔案,並將 MSBuild 屬性設定 AndroidLinkTool 為 r8:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  <AndroidLinkTool>r8</AndroidLinkTool>
</PropertyGroup>

R8 在某些情況下可能會產生新的建置警告或錯誤,相較於 ProGuard,因此專案的 ProGuard 規則可能需要進行一些更新,以解決變更後出現的新警告或錯誤。