Xamarin Android build just hangs when linker is enabled

517 views Asked by At

I have a Xamarin.Android project that hangs when attempting to build the solution in Release configuration. I've narrowed it down to an issue with the linker - if the linker is switched off, it all builds fine.

I've done the build with higher verbosity and even using msbuild from the command line (which suggests it's not an IDE problem), the result is the same. The build output just up to the point where it hangs reads:

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

And it really hangs, like a thread deadlock or something. There's no way to cancel the build, you need to just quit the IDE (similarly, ^C in the terminal does nothing either).

This only seems to affect this one Xamarin project I have (many others with similar configurations build fine). At this stage, I'm really just hoping to find a way to get visibility on what's going wrong.

Any hints would be appreciated.

2

There are 2 answers

1
Mick Byrne On BEST ANSWER

This is not my solution, but the issue was raised and a workaround shared over at the issues list on the Xamarin Android GitHub project at https://github.com/xamarin/xamarin-android/issues/3852

The fix is to remove explicit support for Nullable reference types (<Nullable>enable</Nullable>) from the project file.

For example, in my project file with three configuration/platform PropertyGroups, remove the lines with <Nullable>enable</Nullable>, like:

@@ -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" />
0
Ganso Doido On

Same problem here. Using Visual Studio for Mac, the Deploy step hangs on the exact same spot.

But using Jetbrains Rider on the same codebase it all works fine. I can deploy and debug my Android App just fine.

Linker configuration:

Linker configuration