Solution 1 :
Android build error – The LinkAssemblies task failed unexpectedly
You may see an error message The “LinkAssemblies” task failed unexpectedly when building a Xamarin.Android project that uses Forms.
This happens when the linker is active (typically on a Release build to reduce the size of the app package); and it occurs because the Android targets aren’t updated to the latest framework.
(More information:Platform Support
Important Note
-
You can programmatically obtain information about an assembly by using
reflection. For more information, see Reflection (C#) or Reflection (Visual
Basic). -
You can load an assembly just to inspect it by using the MetadataLoadContext
class in .NET Core and the Assembly.ReflectionOnlyLoad or
Assembly.ReflectionOnlyLoadFrom
methods in .NET Core and .NET Framework.
Additional Note
Problem :
I’m new to Xamarin, pulled a project from a repo that’s failing to Archive APK for MyApplication.Android project. It builds successfully, even creates the APK file if linker is set to ‘None’. But when I try to install on my device i get the error ‘App not installed’
When I set the Linker to ‘SDK Assemblies Only’ or ‘SDK and User Assemblies’ I’m getting following error while building on Release mode.
It’s failing to resolve reference to IAppInformationFinder
which is an Interface defined in another project within the same solution. And yes, it’s been referenced in the .android project.
Error The "LinkAssemblies" task failed unexpectedly.
Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA2006: Could not resolve reference to 'StevensPINApplication.Interfaces.IAppInformationFinder' (defined in assembly 'StevensPINApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null') with scope 'StevensPINApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. When the scope is different from the defining assembly, it usually means that the type is forwarded. ---> Mono.Cecil.ResolutionException: Failed to resolve StevensPINApplication.Interfaces.IAppInformationFinder
at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference)
at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
at Mono.Linker.Steps.MarkStep.MarkInterfaceImplementation(TypeDefinition type, InterfaceImplementation iface)
at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type)
at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)
at Mono.Linker.Steps.MarkStep.Initialize()
at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
at Mono.Linker.Pipeline.Process(LinkContext context)
at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
--- End of inner exception stack trace ---
at Java.Interop.Tools.Diagnostics.Diagnostic.Error(Int32 code, Exception innerException, String message, Object[] args)
at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
at Xamarin.Android.Tasks.LinkAssemblies.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
This issue been raised multiple times with different error, and i’ve tried almost every possible solution proposed online but it didn’t work.
Set the Target Framwork to the latest on the system.
It’s so annoying that before getting to the actual requirement, i’m stuck in the build process right in the beginning.
I’m using VS2017. Just to add here i’ve tried on VisualStudio 2015 & 2019 where it was failing to load to start with. It’s to do with MSBUILD issue.
Comments
Comment posted by AlphaTry
Yeah i’ve read somewhere the same what you suggested, tried setting it to Android 9.0 (Pie) and same result. When linker set to none, it does creates APK successfully. But while installing i’m getting ‘App not Installed’ error on my device.
Comment posted by Nadeem Taj
I appreciate your courage to get things done. I would be so glad to help you in order to find a workaround for you. If you provide complete environment detail such as (os, version, architecture, device info and other information if you think will or can help).
Comment posted by AlphaTry
Windows 10, VS2017 Community v15.9.25, .Net 2.0, samsung s10+
Comment posted by learn.microsoft.com/en-us/xamarin/xamarin-forms/troubleshooting/…
During troubleshooting did you get a chance to look this reference.