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

Xamarin Android应用构建报错:BuildConfig被多次定义

解决Xamarin Android构建时com.getkeepsafe.relinker.BuildConfig重复定义错误
  • 排查依赖树,定位重复引用来源
    打开Visual Studio的NuGet包管理器,切换到「已安装」标签,查看所有依赖包,找出哪些包间接引用了Xamarin.Android.ReLinker。也可以用命令行执行:

    dotnet list package --include-transitive
    

    在输出中搜索relinker相关条目,确认是否存在多个版本或重复引入的情况。

  • 强制统一relinker版本
    编辑项目的.csproj文件,添加明确的PackageReference来指定唯一的Xamarin.Android.ReLinker版本,覆盖所有间接依赖的版本:

    <PackageReference Include="Xamarin.Android.ReLinker" Version="1.4.4" PrivateAssets="all" />
    

    选择最新的稳定版本号,PrivateAssets="all"确保该依赖不会传递给其他项目。

  • 排除重复的库引用
    如果是某NuGet包间接引入了重复的relinker,可在该包的引用中排除runtime资产:

    <PackageReference Include="YourProblemPackage" Version="x.x.x">
      <ExcludeAssets>runtime</ExcludeAssets>
    </PackageReference>
    

    若存在直接引用的重复jar文件,在.csproj中标记排除(替换路径为错误提示中重复的jar路径):

    <AndroidLibraryReference Include="obj\Debug\130\lp\132\jl\bin\classes.jar">
      <Exclude>true</Exclude>
    </AndroidLibraryReference>
    
  • 清理NuGet缓存并重建
    执行命令清理本地NuGet缓存:

    dotnet nuget locals all --clear
    

    然后在Visual Studio中执行「恢复NuGet包」,再重新清理并构建项目。

  • 临时绕过:调整R8/ProGuard配置(不推荐)
    若以上方法均无效,可在ProGuard.cfg或r8.cfg中添加规则忽略重复类:

    -dontwarn com.getkeepsafe.relinker.BuildConfig
    -keep class com.getkeepsafe.relinker.BuildConfig { *; }
    

    此方法仅作为临时 workaround,建议优先解决依赖重复的根源问题。

内容的提问来源于stack exchange,提问作者Ovidiu Midrigan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 08:11:28