You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xamarin.Forms项目MSBuild报XA1023,切换d8后遇数组越界问题求助

解决Xamarin.Forms项目中MSBuild执行的两个错误

错误1:XA1023: 使用DX DEX编译器不被支持

报错信息:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(515,3): 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'.

解决方法:

  • 通过Visual Studio for Mac设置:右键项目 → 选项 → Android构建 → 高级 → 在“DEX编译器”下拉菜单选择d8,保存设置。
  • 手动编辑项目文件:打开项目的.csproj文件,添加或修改以下MSBuild属性:
    <PropertyGroup>
      <AndroidDexTool>d8</AndroidDexTool>
    </PropertyGroup>
    

错误2:java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4

设置AndroidDexTool为d8后出现该数组越界异常,可尝试以下步骤解决:

  • 检查Java SDK版本兼容性:Xamarin.Android 12.2.8.3要求使用Java 11,若当前使用Java 8,需切换到Java 11。在Visual Studio for Mac中:偏好设置 → SDK Locations → Android → Java SDK位置选择Java 11的路径。
  • 彻底清理并重建项目:删除项目的bin和obj文件夹,点击菜单中的“项目 → 清理解决方案”,之后重新构建项目。
  • 更新相关NuGet包:当前使用的Xamarin.Forms 4.5.0.657版本较旧,与Xamarin.Android 12.2存在兼容性问题。建议将Xamarin.Forms更新到兼容Android 12的版本(如5.x或更高),同时检查其他依赖NuGet包,确保版本与目标Android 12.0兼容。
  • 添加d8额外编译参数:在.csproj文件中添加以下属性,尝试禁用脱糖(desugaring):
    <PropertyGroup>
      <AndroidD8ExtraArgs>--no-desugaring</AndroidD8ExtraArgs>
    </PropertyGroup>
    
  • 检查项目资源与依赖库:排查项目中是否存在损坏的资源文件,或引入了与d8编译器不兼容的第三方库,尝试移除或替换这类库后重新构建。

内容的提问来源于stack exchange,提问作者Narender Reddy Manikanti

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 19:35:38