The "LinkAssemblies" task failed unexpectedly
Asked Answered
Z

12

40

When we are trying to build a xamarin forms project in release mode, we are getting the error:

C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(5,5): Error MSB4018: The "LinkAssemblies" task failed unexpectedly.
Xamarin.Android.XamarinAndroidException: error XA2006: Reference to metadata item 'System.Void Android.Widget.AbsListView::SetSelectionFromTop(System.Int32,System.Int32)' (defined in 'Xamarin.Forms.Platform.Android, Version=1.3.3.0, Culture=neutral, PublicKeyToken=null') from 'Xamarin.Forms.Platform.Android, Version=1.3.3.0, Culture=neutral, PublicKeyToken=null' could not be resolved. ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void Android.Widget.AbsListView::SetSelectionFromTop(System.Int32,System.Int32)
   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 Xamarin.Android.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__20.MoveNext() (MSB4018) (XXX.Android)

How can we resolve this? We have tried cleaning and building again. Even closing xamarin studio and restarting it. Nothing seems to work.

We are on the latest release of xamarin forms and xamarin forms labs. The minimum android API level we are using is 17. I even tried minimum sdk version 20.

Some more details:

Xamarin Studio
Version 5.7 (build 661)
Installation UUID: f97e711d-1fe0-450f-a3bb-2d9b972ab295
Runtime:
    Microsoft .NET 4.0.30319.0
    GTK+ 2.24.22 (MS-Windows theme)
    GTK# 2.12.26

Xamarin.Android
Version: 4.20.0 (Indie Edition)
Android SDK: C:\Users\Kartik\AppData\Local\Android\android-sdk
    Supported Android versions:
        2.1    (API level 7)
        2.2    (API level 8)
        2.3    (API level 10)
        3.1    (API level 12)
        4.0    (API level 14)
        4.0.3  (API level 15)
        4.1    (API level 16)
        4.3    (API level 18)
        4.4    (API level 19)
        4.4.87 (API level 20)
        5.0    (API level 21)
Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_39
java version "1.6.0_39"
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) Client VM (build 20.14-b01, mixed mode, sharing)

Build Information
Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 11:27:37-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

Operating System
Windows 6.2.9200.0 (64-bit)
Zabrze answered 10/2, 2015 at 4:45 Comment(0)
C
25

Apparently, this is a known issue: Xamarin Forms needs the TargetAndroidVersion to be 21. (In the config GUI, this is entitled "Compile using Android version:")

Cytosine answered 12/2, 2015 at 15:50 Comment(4)
Well this error has again resurfaced. And I have my TargetAndroidVersion 21.Zabrze
Hm. Look in the raw project file in a text editor; what do you see in the following element: (my value below)<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>Cytosine
This didn't work for me. You have to check two things: 1) make sure that SDK 21 is actually installed... So head over to your SDK updater and install 21/22 (or later). 2) Change the target version doesn't help, you (also) have to change the 'compile using' to version 21. If you've done that, it should work.Conceptionconceptual
Why should the target be 21? Xamarin.Formds requirements: "Android 4.0.3 (API 15) or higher" NOTE: The target settings should be set to Use latest/Automatic and you should always have the latest release of the Android SDK installed (6.0 at the time of writing): Source: developer.xamarin.com/guides/xamarin-forms/getting-started/…Humber
S
5

In my case problem occured becasue of adding Xamarin.ios.dll to Portable Project references. I have removed that reference and it works now

Sisson answered 25/9, 2017 at 10:35 Comment(0)
S
4

I changed the Linker properties > Linking from Sdk Assemblies Only to Sdk and User Assemblies for the Release configuration.

options

Stradivarius answered 2/6, 2018 at 17:11 Comment(3)
thanks for the hint, for me it was fixed after setting link behaviour to Don't LinkSextodecimo
@Sextodecimo that is generally not a good idea, see the comment on https://mcmap.net/q/398388/-the-quot-linkassemblies-quot-task-failed-unexpectedly by DpedrinhaStradivarius
yes you are right, I kind of thought about that because it reminded me proguard but now that I checked the apk size after your comment I have to search for the true solution. Somehow adding akavache ruined my release builds.Sextodecimo
G
3

In my case the problem was referenced dll Xamarin.iOS in the pcl project. Linking does not work for this assembly. Removing the reference fixed the issue.

Greggs answered 11/11, 2016 at 11:35 Comment(0)
I
1

I also experienced the same problem. After series of trial and errors i found a solution.

In your Manifest set Target Android Version to Android 7.1 (API Level 25 Nougat) or Higher. Set Compile Android Version to Android 7.1 as well.

I hope this helps

Inflate answered 5/2, 2018 at 20:31 Comment(0)
C
0

I fixed it downgrading the Xamarin.Android.Support.v4 to the 21.0.0 version in NuGet Package Manager. Hope that help you

Chichihaerh answered 28/8, 2015 at 6:4 Comment(0)
A
0

I ended up getting this error after changing the Android target version to 9.0. What I noticed is that in the packages.config of the Android project, all the packages were still targeting monoandroid81 instead of monoandroid90.

I solved it by just reinstalling all NuGet packages. This can be done quite easily through the Package Manager Console in Visual Studio by entering:

Update-Package -Reinstall

I recommend taking a backup first, though.

After that all the packages were targeting the correct version and the compilation errors were gone.

Aldas answered 19/7, 2019 at 7:0 Comment(0)
L
0

I had a different root cause for the "LinkAssembliesTask failed" error.

I was upgrading NuGet packages, and messed up the references.

=====

Let's say I had two projects:

  1. NetStandardProject

    • Has a reference to Assembly1.

    • Assembly1 has a class of CoolGuy, with a CoolGuy.Flex() method.

  2. AndroidProject, which references NetStandardProject.

    • Has a reference to Assembly2.

    • Assembly2 has a class of CoolGuy, but no CoolGuy.Flex() method.

The linker was pulling in Assembly2, looking for CoolGuy.Flex(), then blew up with "LinkAssembliesTask failed", stating that it couldn't find the Flex() method. It couldn't because it was looking in the wrong assembly.

The NetStandard project compiled, because it was referencing Assembly1, and didn't really care what AndroidProject was referencing. It's built independently. But when the linker loaded Assembly2, it was using the "wrong" assembly.

I ended up sorta lucking out, and realized that one of the assemblies was unused, so I removed it, and the build succeeded.

Hope that helps someone down the line.

=====

Bonus: If you want to see which assembly it's choosing to search, let the build fail, then go to the {project}\obj{profile}{android_version}\android\assets folder, and find the dll. You will likely be able to verify that it's not there, and give you a starting point to understanding why it's failing.

Lepus answered 7/8, 2019 at 22:32 Comment(0)
B
0

Change linking to old mono android to new mono android. It worked for me. I changed from Monoandroid 8.0 to Monoandroid 9.0 of some dll's like Xamarin.Android.Platforms etc..

Birthright answered 14/7, 2020 at 10:29 Comment(0)
T
-1

In my chase I have changed the linker property ( Linker --> Linking ) to 'None'. I am using visual studio 2017 RC

Toolmaker answered 2/12, 2016 at 11:31 Comment(3)
Yeah, but turning the linker off doesn't fix the problem with the linker, does it? It increases the apk size significantly and xamarin apps are already too big, so this is not really an option.Homothallic
This fixes the problem with VS Enterprise 2017, though increases the app sizeGoldofpleasure
this is not a solution. why are you even posting something like that? all xamarin newbies will get on your trap. shame to not use linking. you should even use full linking.Repine
A
-2

Jus I changed linking from "NONE" to "sdk and users assembly" and I ran my solution, and the issue has been solved. after that you can change "sdk and users assembly" to "NONE" and run your project without any issue.

But the release file size may be will be change.

enter image description here

Anastassia answered 22/8, 2016 at 12:47 Comment(0)
D
-3

I´ve solved that changing Android Linker Behavior option in options > Android Builder > Linker from "Link sdk Assemblies Only" to "don't link".

Diatomite answered 8/3, 2015 at 17:45 Comment(2)
Sorry but that's not solving the problem. If you select "don't link" you are turning off the linker, meaning that you are deploying the whole BCL in your APK, including all the components that you don't need. This makes your APK huge.Conceptionconceptual
This approach will resolve the symptom, but is not directly the cause of the issue; rather invalid Android targets are.Underworld

© 2022 - 2024 — McMap. All rights reserved.