Problem building in release mode with linking

FrancisRathFrancisRath NOMember, University

Hello,

I have some problems building my android app in release mode with linking enabled. I only have an android target at this point.

I get the following exception:

Error   5   The "LinkAssemblies" task failed unexpectedly.
Xamarin.Android.XamarinAndroidException: error XA2006: Reference to metadata item 'Android.Gms.Maps.Model.Marker Android.Gms.Maps.GoogleMap/InfoWindowClickEventArgs::get_P0()' (defined in 'Xamarin.Forms.Maps.Android, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null') from 'Xamarin.Forms.Maps.Android, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null' could not be resolved. ---> Mono.Cecil.ResolutionException: Failed to resolve Android.Gms.Maps.Model.Marker Android.Gms.Maps.GoogleMap/InfoWindowClickEventArgs::get_P0()
   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() Werkak.Mobile.Android

I am using Xamarin.Forms and Xamarin.Forms.Maps, both version 1.3.0.6284-pre3.

Any ideas what could be wrong? Release builds without linking works, but gives me a 42 MB apk for a pretty small app..

Answers

  • dsteckdsteck ✭✭ USMember ✭✭

    I was having a similar problem yesterday. Be sure to upgrade your Xamarin.Android.Support.v13 and .v4 too.

  • JimKoehlerJimKoehler ✭✭ USMember ✭✭

    I'm having that same problem with:

    • Xamarin.Forms 1.3.0.6286-pre4
    • Xamarin.Forms.Maps 1.3.0.6286-pre4
    • Xamarin.Android.Support.v4 21.0.3.0
    • Xamarin.Android.Support.v13 21.0.0.3

    Are there newer Xamarin.Android.Support.v4 and .v13 packages?

  • ShashankELShashankEL USMember

    All my support libraries are up to date but I still have the problem. Please let me know, if you have found a resolution

  • TheRealJasonSmithTheRealJasonSmith Xamurai USXamarin Team Xamurai

    You might need to tell the linker to preserve the type (we dont control preservation of non-Forms types).

    There is documentation on this here: http://developer.xamarin.com/guides/cross-platform/advanced/custom_linking/

  • ShashankELShashankEL USMember

    @JasonASmith InfoWindowClickEventArgs is a class inside Android.Gms.Maps.GoogleMap, how will the linker description file look like. The link shared has example only for methods and fields.

  • VincentPoirierVincentPoirier ✭✭ CAMember ✭✭

    I tried adding the Xamarin.Android.Support.v13 and Xamarin.Android.Support.v4 to my PCL and Android project and nothing changed sadly.
    Are those support packages supposed to be on both PCL and specific-platform projects?
    I'll go try what Jason suggests.

  • VincentPoirierVincentPoirier ✭✭ CAMember ✭✭
    edited December 2014

    Here's a follow up. We tried playing with the Android linker options a little. See attached image.

    Don't link compiles, but doesn't seem to generate any .apk file which seems only logical.
    All other options cause this thread's error. If I understand well, there is code somewhere that makes the linker angry and if we put [Preserve] on it, it would successfully compile?

    Instructions unclear, installed windows 3.1 instead.

  • VincentPoirierVincentPoirier ✭✭ CAMember ✭✭
    edited December 2014

    Hi @JasonASmith‌, I put below the console log about the release build that's failing for us. We read the documentation and according to your post, does it mean we should add the preserve tag to Xamarin.Forms.BindableProperty?

    If it can help anyone progress on this subject, I don't mind providing our source code so anyone from Xamarin.Forms can reproduce the problem.

    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 'Xamarin.Forms.BindableProperty Xamarin.Forms.BindableProperty::Create(System.Linq.Expressions.Expression`1<System.Func`2<!!0,!!1>>,!!1,Xamarin.Forms.BindingMode,Xamarin.Forms.BindableProperty/ValidateValueDelegate`1<!!1>,Xamarin.Forms.BindableProperty/BindingPropertyChangedDelegate`1<!!1>,Xamarin.Forms.BindableProperty/BindingPropertyChangingDelegate`1<!!1>,Xamarin.Forms.BindableProperty/CoerceValueDelegate`1<!!1>)' (defined in 'OxyPlot.XamarinForms, Version=2014.1.546.0, Culture=neutral, PublicKeyToken=null') from 'OxyPlot.XamarinForms, Version=2014.1.546.0, Culture=neutral, PublicKeyToken=null' could not be resolved. ---> Mono.Cecil.ResolutionException: Failed to resolve Xamarin.Forms.BindableProperty Xamarin.Forms.BindableProperty::Create(System.Linq.Expressions.Expression`1<System.Func`2<!!0,!!1>>,!!1,Xamarin.Forms.BindingMode,Xamarin.Forms.BindableProperty/ValidateValueDelegate`1<!!1>,Xamarin.Forms.BindableProperty/BindingPropertyChangedDelegate`1<!!1>,Xamarin.Forms.BindableProperty/BindingPropertyChangingDelegate`1<!!1>,Xamarin.Forms.BindableProperty/CoerceValueDelegate`1<!!1>)
       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) (Klaim.Droid)
    

    There's also two warnings that come with it. It could be related.

    C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(5,5): Warning MSB3247: Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Runtime" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.IO" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Net.Primitives" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Net.Http.Primitives" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.2.28.0" newVersion="4.2.28.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Net.Http" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Threading.Tasks" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /></dependentAssembly></assemblyBinding> (MSB3247) (Klaim.Droid)

    C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(3,3): Warning MSB3247: Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Net.Primitives" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Threading.Tasks" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Net.Http" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Net.Http.Primitives" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.2.28.0" newVersion="4.2.28.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Net.Requests" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Runtime" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.IO" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /></dependentAssembly></assemblyBinding> (MSB3247) (Klaim.Droid)

    This seems to be more about the Microsoft.Net.Http package. We have it on both the PCL and the Android project.

  • VincentPoirierVincentPoirier ✭✭ CAMember ✭✭

    By digging in the bigass log, I found the from part that specifies OxyPlot. After I removed the OxyPlot packages, I was able to compile perfectly.

    In your case Francis, it's something in Xamarin.Forms.Maps.Android that's not being linked correctly. Have you found the solution? Have you tried applying the preserve tag on the get_P0() function?

  • FrancisRathFrancisRath NOMember, University

    I tried to figure out what to put in the custom linking xml-file, but didn't really get anywhere. I also updated to 1.3 final without any further success.

  • kaolickkaolick ✭✭ DEMember ✭✭

    @FrancisRath‌ I ran into the same problems. It seems that the the current stable version of Xamarin.Forms.Maps (1.3.0.6292) isn't best friends with the latest GooglePlayServicesLib 22.0.0. In fact it's not working with v19.0.0.1 either (ran into other errors). So what I did was downgrading it to 16.0.0.0. This version works with the Xamarin.Forms.Maps version mentioned above.

    To test it I recommend you setup a new blank shared solution, update the packages and add Xamarin.Forms.Maps package. This will automatically install GooglePlayServices v16.0.0. This will compile in release mode. But when you update GPS to v22 it won't (don't forget to set targetSDK to the latest version in the manifest and to set Java heap size to 1G, that did cost me some time as well).

    Another thing that I ran into was that Google changed its Location API. So when you update your GooglePlayServices to the latest version v22 you can't use classes like LocationClient anymore. There's still no documentation on Xamarin.com for using the latest Location API (see here) on Android. But it's very much straight forward to code in C# when you look at the Java code.

    Hope they gonna fix that soon. Issues like this are just unacceptable. Hope this will help you.

  • DarrellBookerDarrellBooker ✭✭ USMember ✭✭

    @JasonASmith‌ I see the Bugzilla comment from you earlier today that says Resolved in 1.3.2-pre1. When will that release be available?

  • ghostmanghostman BRMember

    So far anyone have come with a work around on this issue?
    I'm working with Xamarin.Forms/Xamarin.Forms.Maps version 1.3.4.6332 and Xamarin.GooglePlayServices version 22.0.0.2.

    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 'Xamarin.Forms.BindableProperty Xamarin.Forms.BindableProperty::Create(System.Linq.Expressions.Expression1<System.Func2<!!0,!!1>>,!!1,Xamarin.Forms.BindingMode,Xamarin.Forms.BindableProperty/ValidateValueDelegate1<!!1>,Xamarin.Forms.BindableProperty/BindingPropertyChangedDelegate1<!!1>,Xamarin.Forms.BindableProperty/BindingPropertyChangingDelegate1<!!1>,Xamarin.Forms.BindableProperty/CoerceValueDelegate1<!!1>)' (defined in 'Xamarin.Forms.Labs, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null') from 'Xamarin.Forms.Labs, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null' could not be resolved. ---> Mono.Cecil.ResolutionException: Failed to resolve Xamarin.Forms.BindableProperty Xamarin.Forms.BindableProperty::Create(System.Linq.Expressions.Expression1<System.Func2<!!0,!!1>>,!!1,Xamarin.Forms.BindingMode,Xamarin.Forms.BindableProperty/ValidateValueDelegate1<!!1>,Xamarin.Forms.BindableProperty/BindingPropertyChangedDelegate1<!!1>,Xamarin.Forms.BindableProperty/BindingPropertyChangingDelegate1<!!1>,Xamarin.Forms.BindableProperty/CoerceValueDelegate1<!!1>)
    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.d__20.MoveNext() (MSB4018) (MASS.Droid)

  • ghostmanghostman BRMember

    On my case it was the Xamarin.Forms.Labs the problem. This https://bugzilla.xamarin.com/show_bug.cgi?id=25803 solve my case.

  • drmadrma USMember

    I have the same problem like @VincentPoirier with Xamarin.Forms.BindableProperty. Any success with that?

  • AlessandroCaliaroAlessandroCaliaro ✭✭✭✭✭ ITMember ✭✭✭✭✭

    To solve the problem I've removed xam.labs packages....

  • ApurvaGoyalApurvaGoyal ✭✭ USMember ✭✭
    edited March 2015

    I am also getting same exception. I am using following versions-

    Xamarin.Forms.Labs: 1.2.1 pre-2
    Xamarin.Forms: 1.3.2

    Anyone was able to get this worked out? This is a serious issue for me for I wont be able to release the app. And I cant remove the xamarin.forms.labs package. Plus the https://bugzilla.xamarin.com/show_bug.cgi?id=25803 shows that in 1.2.1 pre-2 this issue was resolved.

  • AlessandroCaliaroAlessandroCaliaro ✭✭✭✭✭ ITMember ✭✭✭✭✭

    @ApurvaGoyal you could try to use "Labs" sources, not the package...

  • ApurvaGoyalApurvaGoyal ✭✭ USMember ✭✭

    Here is the stack trace that I get-

    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.2.0, Culture=neutral, PublicKeyToken=null') from 'Xamarin.Forms.Platform.Android, Version=1.3.2.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.d__20.MoveNext() (MSB4018) (wpMobile.Android)

  • LucaFabbriLucaFabbri ITMember

    Same issue here but it looks it refers to the xamarin forms library, so that it doesn't make sense to preserve types as explained above. Anubody from Xamarin can help?

    /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Error executing task LinkAssemblies: error XA2006: Reference to metadata item 'System.Void Android.Widget.AbsListView::SetSelectionFromTop(System.Int32,System.Int32)' (defined in 'Xamarin.Forms.Platform.Android, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null') from 'Xamarin.Forms.Platform.Android, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null' could not be resolved. (mePregnant.Droid)

  • ramonesteban78ramonesteban78 ✭✭ ESUniversity ✭✭

    Same issue here:

    /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Error executing task LinkAssemblies: error XA2006: Reference to metadata item 'System.Void Android.Widget.AbsListView::SetSelectionFromTop(System.Int32,System.Int32)' (defined in 'Xamarin.Forms.Platform.Android, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null') from 'Xamarin.Forms.Platform.Android, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null' could not be resolved.

    Any help would be appreciated.

    Regards

  • ramonesteban78ramonesteban78 ✭✭ ESUniversity ✭✭

    @LucaFabbri did you find a solution for this?

    The only way it's working for me is putting the Link Assemblies to Don't Link, but it generates a 37MB apk which is not acceptable.

    Regards

  • Tanuj.4838Tanuj.4838 USMember

    If you are having this error, and there is some package is showing in message i.e json.net. In this please make sure all your project use the same version of the package in all project in the solution.

  • Emixam23Emixam23 ✭✭✭ USMember ✭✭✭

    Does someone found something? :/

  • Henrique.7684Henrique.7684 ✭✭ USMember ✭✭
    edited July 2017

    Hi! I was experiencing this issue. In my case chaning target to 21 didn't work. I fixed the linking problem by inspecting project.Android.csproj and I noticed that this line:
    <Reference Include="Xamarin.Android.Support.v7.AppCompat"> was the only one that didn't specify a version...
    so changing it to this next line fixed my problem:
    <Reference Include="Xamarin.Android.Support.v7.AppCompat, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">

Sign In or Register to comment.