The "LinkAssemblies" task failed unexpectedly
If you are XAMARIN developer then you might have encountered this error "The "LinkAssemblies" task failed unexpectedly" in XAMARIN.FORMS projects. something like below
Very irritating error as sometimes you will not get any info in the stack trace which shows the actual error that can be fixed.
If we look at the stack trace :
Error The "LinkAssemblies" task failed unexpectedly.
Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA2006: Reference to metadata item 'System.Void Android.Support.V4.Widget.DrawerLayout::AddDrawerListener(Android.Support.V4.Widget.DrawerLayout/IDrawerListener)' (defined in 'Xamarin.Forms.Platform.Android, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null') from 'Xamarin.Forms.Platform.Android, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' could not be resolved. ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void Android.Support.V4.Widget.DrawerLayout::AddDrawerListener(Android.Support.V4.Widget.DrawerLayout/IDrawerListener)
at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
at Mono.Linker.Steps.MarkStep.ProcessQueue()
at Mono.Linker.Steps.MarkStep.Process()
at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
at Mono.Linker.Pipeline.Process(LinkContext context)
at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
at Xamarin.Android.Tasks.LinkAssemblies.Execute()
--- 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()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
By looking above error you cant predict what actually happening and what I need to change in order to remove this error.
And this error will not come when you will run your project in debug mode. You will encounter this error when you will go for deployment or run in release mode.
And you will be more irritated when in forums you will see by changing something , other are able to resolve the issue but you are not. You also did the same thing but issue still exists. :p
So, here are the some causes due to which you might face the above issue.
1. You are using file/image having name containing character '-' or '_' . So rename the file to remove any special character and rebuild your solution after cleaning it. Check if error is gone or not. If error is still there, then try the next step.
2. Check the linker option. If it is something other than "Sdk Assemblies Only" then change it to "Sdk Assemblies Only" and then clean and rebuild and see if error gone or still there.
To find the below screen, Right click on the Android project, Select Properties then select Android Options and select Linker tab.
see below image:
If you still get error by changing the linker option to "Sdk Assemblies Only" then select "none" and rebuild the project and it will generate the apk and app will run in release mode but the size of the app will increase approximately 10 times. So do not try this option until unless no other option works.
3.If you are still getting the error after trying the above options then you need to check the "Minimum Android to Target". Right click on the Android project and select properties, Under Application option check if the Minimum Android to target is selected API level 19 i.e. Android 4.4 Kitkat, if it is not then set it to API level 19 and set "Target Android Version" to "Use Compile Using SDK version".
See below image for reference
Save the application. Clean and rebuild to check if the error removed or still exists. If error is there then try the below option
4. The last option you should try to upgrade the Xamarin.Forms to latest stable release version which is 2.3.3.175 (when this post was written). Do not update the other related libraries, updating the xamarin.forms will automatically upgrade other dependent libraries.
I am 100% sure that if you follow above 4 steps then you will not get this error and if you are still getting this error , then write to XAMARIN, they only can help in that case,
Great post and more informative!keep sharing this!
ReplyDeleteinformatica mdm training
Informatica MDM Training in Chennai
Big Data Analytics Training in Chennai
Blockchain course
Best Informatica Training in Chennai
Node JS Training in Chennai
Xamarin Training in Chennai