Xfx.Controls icon indicating copy to clipboard operation
Xfx.Controls copied to clipboard

Build issue in Release mode (Linking SDK Assemblies)

Open hemantramu opened this issue 5 years ago • 19 comments

We are using the XfxControls package in a Xamarin.Forms app (Droid and iOS). The Xamarin Forms version is 3.6.0.293080. When we try to compile our primary Droid platform project, we get a build error that the "LinkAssemblies task failed unexpectedly." The actual build error is quoted below. When we build the project in "Debug" mode, it works fine. If we select "Don't Link" in the Linker Behavior section of the Droid project options in the Release configuration, the build completes.

Version Number of Control: 1.1.3 / 1.2.1 Device Tested On: Debug Working Simulator Tested On: N/A Affects iOS - Not Tested Yet Android (Min version API19, target version API28, Xamarin Android version 9, SDK Tools version 26.1.1, SDK Platform Tools version 28.0.1, SDK Build Tools version 27.0.3) Expected Behavior Project compiles without any linker errors

Actual Behavior Droid project compilation fails with linker exception like this:

\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly. \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: Mono.Linker.MarkException: Error processing method: 'System.Void Xfx.Controls.Droid.Renderers.XfxCardViewRendererDroid::Xamarin.Forms.Platform.Android.IVisualElementRenderer.add_LayoutChange(System.EventHandler1<Android.Views.View/LayoutChangeEventArgs>)' in assembly: 'Xfx.Controls.Droid.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void Xamarin.Forms.Platform.Android.IVisualElementRenderer::add_LayoutChange(System.EventHandler1<Android.Views.View/LayoutChangeEventArgs>) \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference) \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference) \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method) \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessQueue() \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: --- End of inner exception stack trace --- \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessQueue() \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue() \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: at Mono.Linker.Steps.MarkStep.Process() \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context) \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: at Mono.Linker.Pipeline.Process(LinkContext context) \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context) \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res) \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: at Xamarin.Android.Tasks.LinkAssemblies.Execute() \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() \2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2129,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

hemantramu avatar Apr 11 '19 18:04 hemantramu

Before I start digging into this, did you ensure you did a full clean/delete bin/rebuild? Sometimes Visual Studio gets confused.

ChaseFlorell avatar Apr 11 '19 18:04 ChaseFlorell

Yes i have done full clean/delete bin/rebuild and even nuget downgraded / upgraded the package as well

hemantramu avatar Apr 11 '19 19:04 hemantramu

Any update on the above issue

hemantramu avatar Apr 15 '19 09:04 hemantramu

I have this issue too, I tried everything to solve it, nothing helped me. Please @ChaseFlorell, try to fix it. Thanks.

AbdulazizDbekhi avatar Apr 23 '19 06:04 AbdulazizDbekhi

Still facing the same issue in different solutions as well

hemantramu avatar May 02 '19 09:05 hemantramu

I'm also facing this issue. I did some research on this and looks like it's related with this PR, specifically this change which removes the LayoutChange EventHandler from IVisualElementRenderer. I did some tests that show the following:

VS Community 2019 16.0.3; Xamarin Android: 9.2.3.0; SDK Tools: 26.1.1; SDK Platform Tools: 28.0.1; Xfx.Controls: 1.2.1; Linking: SdkAssemblies; Release;

Tests on a newly created Blank App and the Xfx.Controls.Example(from this source, referencing library directly) changing only XF version:

Blank App

  • 3.5.0.129452 - Success
  • 3.5.0.169047 - Success
  • 3.5.0.274416 - Failing
  • 3.6.0.220655 -Failing
  • 3.6.0.344457 -Failing
  • 4.0.0-pre9 - Failing

Example App

  • 3.5.0.129452 - Success
  • 3.5.0.169047 - Success
  • 3.5.0.274416 -Failing
  • 3.6.0.220655 -Failing
  • 3.6.0.344457 -Failing

So, the PR is said to be merged on XF 3.6.0 but it starts to fail if we reference XF 3.5.0.274416 which in fact does not contain the LayoutChange EventHandler on the interface.

Then I tried updating the Xfx.Controls XF reference to versions >= 3.5.0.274416 and it succeeded on these scenarios:

  • Xfx.Controls.Example.(Standard, iOS, Droid): XF 3.5.0.274416 & Xfx.Controls.(Standard, iOS, Droid): 3.5.0.274416
  • Xfx.Controls.Example.(Standard, iOS, Droid): XF 3.6.0.344457 & Xfx.Controls.(Standard, iOS, Droid): 3.5.0.274416
  • Xfx.Controls.Example.(Standard, iOS, Droid): XF 3.6.0.344457 & Xfx.Controls.(Standard, iOS, Droid): 3.6.0.344457

While Xfx is not updated to a newer XF version, I went in search of a workaround for my project, tried configuring custom linking, overwriting XfxCardViewRenderer and using falseflag but nothing worked. I also tried some fixes on Xfx code without updating XF version but didn't come out with nothing...

I hope my info helps on this. 😄

MDemetrio avatar May 15 '19 06:05 MDemetrio

Having the same issue here, the only way to make it work is not to linked assemblies on the android project settings, but of course, these will raise the APK size quite a fair amount.

eamiguinho avatar May 21 '19 16:05 eamiguinho

+1 with the same problem when upgrading to Xamarin 4 starts giving Linker errors

Laboss avatar Jun 17 '19 15:06 Laboss

MDemetrio did a great job detailing the bug, so please fix it quickly

I have the same problem when running on Xamarin.Forms.3.6.0.344457

In debug mode there's no error, but in release mode there are linking erros

rodrigueslg avatar Jun 18 '19 23:06 rodrigueslg

+1 with same problem in debug mode too with XF 4.1. Visual Studio 2019 16.2.0 and latest XFx control.

NiketanMhatre avatar Jul 25 '19 16:07 NiketanMhatre

Me too facing the same problem .. any updates ?

mahmoudAbdin avatar Aug 19 '19 07:08 mahmoudAbdin

I have the same problem... Any solution?

MRomeror avatar Oct 17 '19 11:10 MRomeror

I have the same issue. I have created a PR to update packages. In my initial tests this issue seems to be fixed with these updates.

DeShrike avatar Nov 21 '19 14:11 DeShrike

This issue is related to #44 , Please @ChaseFlorell is it possible, provide us a solution.

The only way to make it work is not to linked assemblies on the android project settings, but of course, these will raise the APK size quite a fair amount. as @eamiguinho said.

Thanks in advance.

rubberydev avatar Dec 23 '19 18:12 rubberydev

I have this error, any solution?

pablortpo avatar Jan 24 '20 16:01 pablortpo

Yes there is a solution. The solution provided @DeShrike is working... but because the owner (@ChaseFlorell ) hasn't accept @DeShrike pull request yet, you will have to do it by yourself (and in my opinion it's a very ugly way to fix the problem) What I did :

  1. Download Xfx.Controls sources. Update Xamarin.Forms references from version 3.5.0.129452 to version 3.6.0.709228
  2. Compile Xfx.Controls , Xfx.Controls.Droid, Xfx.Controls.iOS to get dlls
  3. In your main project, instead of referencing Xfx Nuget package, reference the dlls you just compiled.
  4. Try to run your main project with "linking SDK Assemblies", it should work.

fchihe avatar Jan 29 '20 13:01 fchihe

Thanks @fchihe , i will try to do.

pablortpo avatar Feb 16 '20 01:02 pablortpo

Thanks @fchihe this worked for us.

pavanalluri007 avatar Feb 21 '20 07:02 pavanalluri007

We were able to fix this issue following this process;

  • Clone XFXControl repository

  • Update the Android Support Nuggets to 28.0.0.3

  • Update Xamarin Forms Nugget Package to 3.6+

  • Rebuild the Xamarin Forms Shared Project, Android and iOS projects

  • Copy the dlls for the three projects xfxcontrol, xfxcontrol.droid, xfxcontrol.ios

  • Uninstall the xfxxontrol Nuget Package and add the dlls as references in the shared Xamarin forms project

  • Clean the project and Rebuild in Release mode... It should build fine now!

AlisuTech avatar Sep 17 '20 16:09 AlisuTech