Xamarin Android 构建仅在启用链接器时挂起

Xamarin Android build just hangs when linker is enabled

我有一个 Xamarin.Android 项目在尝试在发布配置中构建解决方案时挂起。我已将其缩小为链接器的问题 - 如果关闭链接器,则一切正常。

我已经完成了更详细的构建,甚至从命令行使用 msbuild(这表明它不是 IDE 问题),结果是一样的。直到它挂起的地方的构建输出显示为:

Target _LinkAssembliesShrink:
  Building target "_LinkAssembliesShrink" completely.
  Input file "obj/Preview/linksrc/BondiToManly.Android.dll" is newer than output file "obj/Preview/link.flag".
  Task "CreateProperty" skipped, due to false condition; ( '$(AndroidLinkTool)' != '' ) was evaluated as ( '' != '' ).
  Task "MakeDir" skipped, due to false condition; ( '$(AndroidLinkTool)' != '' ) was evaluated as ( '' != '' ).
  Using "LinkAssemblies" task from assembly "/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Build.Tasks.dll".
  Task "LinkAssemblies"
    Processing resource linker descriptor: mscorlib.xml
    Processing resource linker descriptor: Mono.Android.xml
    Processing embedded resource linker descriptor: mscorlib.xml
    Duplicate preserve in descriptor mscorlib.xml from Xamarin.Android.Build.Tasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null of System.AppDomain (Nothing).  Duplicate uses (Fields)
    Duplicate preserve in descriptor mscorlib.xml from Xamarin.Android.Build.Tasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null of System.AppDomainSetup (Fields).  Duplicate uses (Fields)
    Type Mono.ValueTuple has no fields to preserve
    Type System.Reflection.Assembly has no fields to preserve
    Type System.Reflection.Emit.ByRefType has no fields to preserve
    Type System.Reflection.Emit.PointerType has no fields to preserve

它真的挂了,就像线程死锁之类的。没有办法取消构建,你只需要退出 IDE (同样,终端中的 ^C 也什么都不做)。

这似乎只影响我拥有的这个 Xamarin 项目(许多其他具有类似配置的项目构建良好)。在这个阶段,我真的只是希望找到一种方法来了解问题所在。

如有任何提示,我们将不胜感激。

这不是我的解决方案,但在 https://github.com/xamarin/xamarin-android/issues/3852

的 Xamarin Android GitHub 项目的问题列表中提出了问题并共享了解决方法

解决方法是从项目文件中删除对可空引用类型 (<Nullable>enable</Nullable>) 的显式支持。

例如,在我的项目文件中有三个 configuration/platform PropertyGroups,删除带有 <Nullable>enable</Nullable> 的行,例如:

@@ -29,7 +29,6 @@
     <WarningLevel>4</WarningLevel>
     <NoWarn>VSTHRD200</NoWarn>
     <LangVersion>8.0</LangVersion>
-    <Nullable>enable</Nullable>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
@@ -40,7 +39,6 @@
     <WarningLevel>4</WarningLevel>
     <NoWarn>VSTHRD200</NoWarn>
     <LangVersion>8.0</LangVersion>
-    <Nullable>enable</Nullable>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'VLU1|AnyCPU'">
     <DebugSymbols>true</DebugSymbols>
@@ -52,7 +50,6 @@
     <ErrorReport>prompt</ErrorReport>
     <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
     <LangVersion>8.0</LangVersion>
-    <Nullable>enable</Nullable>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="Microsoft.CSharp" />

同样的问题。 将 Visual Studio 用于 Mac,部署步骤挂在完全相同的位置。

但是在同一个代码库上使用 Jetbrains Rider 一切正常。我可以很好地部署和调试我的 Android 应用程序。

链接器配置: