Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the "linkassemblies" task failed for Android Xamarin Forms #1521

Closed
jassmith opened this issue Apr 7, 2018 · 18 comments
Closed

the "linkassemblies" task failed for Android Xamarin Forms #1521

jassmith opened this issue Apr 7, 2018 · 18 comments
Assignees
Labels
Area: Linker Issues when linking assemblies. need-info Issues that need more information from the author.

Comments

@jassmith
Copy link

jassmith commented Apr 7, 2018

From @ExzaSolutions on December 27, 2017 8:25

Bug report best practices: https://github.com/xamarin/Xamarin.Forms/wiki/Submitting-Issues

Description

When the Xamarin Forms Project builds the Android build fails.
The android is set to build to Release,and the linking is set to Sdk Assemblies only.
When it is set to None it builds successfully,but the apk is far too big then.

Steps to Reproduce

  1. Add Nuget Packages to Xamarin Forms Solution
  2. Set Android Project To Release and linking to Sdk Assemblies only.
  3. Build Solution

Expected Behavior

Should build successfully

Actual Behavior

Fails with "LinkAssemblies" task failed unexpectedly. System.NullReferenceException: Object reference not set

Basic Information

Microsoft Visual Studio Community 2017
Version 15.5.2
VisualStudio.15.Release/15.5.2+27130.2010
Microsoft .NET Framework
Version 4.7.02556

Installed Version: Community

Visual Basic 2017 00369-60000-00001-AA801
Microsoft Visual Basic 2017

Visual C# 2017 00369-60000-00001-AA801
Microsoft Visual C# 2017

Visual F# 4.1 00369-60000-00001-AA801
Microsoft Visual F# 4.1

Application Insights Tools for Visual Studio Package 8.10.01106.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.0.31125.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 1.0
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2012 4.0.20601.0
For additional information, visit https://www.asp.net/

ASP.NET Web Frameworks and Tools 2017 5.2.51007.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 15.0.31106.0
Azure App Service Tools v3.0.0

Azure Data Lake Node 1.0
This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio 2.2.9000.1
Microsoft Azure Data Lake Tools for Visual Studio

Azure Data Lake Tools for Visual Studio 2.2.9000.1
Microsoft Azure Data Lake Tools for Visual Studio

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Fabric.DiagnosticEvents 1.0
Fabric Diagnostic Events

JavaScript Language Service 2.0
JavaScript Language Service

Merq 1.1.17-rc (cba4571)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.

Microsoft Azure HDInsight Azure Node 2.2.9000.1
HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service 2.2.9000.1
Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio 1.8
Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service 2.2.9000.1
Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node 1.0
Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools 2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.51120.3

Microsoft Continuous Delivery Tools for Visual Studio 0.3
Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers 1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Mono Debugging for Visual Studio 4.8.4-pre (3fe64e3)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 4.5.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

SQL Server Data Tools 15.1.61710.120
Microsoft SQL Server Data Tools

ToolWindowHostedEditor 1.0
Hosting json editor into a tool window

TypeScript Tools 15.5.11025.1
TypeScript Tools for Microsoft Visual Studio

Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

WebJobs Tools v1.0.0 15.0.31106.0
WebJobs Tools v1.0.0

Xamarin 4.8.0.753 (6575bd113)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 4.8.188 (c5813fa34)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK 8.1.0.25 (HEAD/d8c6e504f)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK 11.6.1.2 (6857dfc)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

  • IDE: MS VS Community 2017
  • Platform Target Frameworks:
    • Android: 8.0
  • Nuget Packages:
- Affected Devices:

Screenshots

Reproduction Link

Copied from original issue: xamarin/Xamarin.Forms#1471

@jassmith
Copy link
Author

jassmith commented Apr 7, 2018

From @samhouts on February 23, 2018 19:50

When you say "Add Nuget Packages to Xamarin Forms Solution", which nuget packages are you referring to? Can you reproduce this with a brand new Xamarin.Forms solution, or does it only seem to happen to your project? Thanks

@jassmith
Copy link
Author

jassmith commented Apr 7, 2018

From @latsson on February 23, 2018 21:0

Is not this a bug in visual studio that has been fixed? Can't find the bug report right now though.

@jassmith
Copy link
Author

jassmith commented Apr 7, 2018

From @PureWeen on February 24, 2018 6:5

This might be a bug with the Android linker

I've seen it come up when you have nugets that still include PCL libraries or pre-netstandard 2.0 libraries and you add them into a netstandard 2.0 projects. I'm still running up against this issue with the Azure IoT libraries

Azure/azure-iot-sdk-csharp#197

I fixed it their by just recompiling them against NetStandard 2.0

I've also noticed this error only comes up if you set it to link both user and full assemblies.

@jassmith
Copy link
Author

jassmith commented Apr 7, 2018

From @ExzaSolutions on February 24, 2018 20:6

Hi,our appsize was 107mb on Android.
While our competitions size was less than 15mb.
We use progaurd and linking against sdk assemblies and got it down to 42MB +-.
Then the error started to popup.
It took a week to figure this out and fix it.
I found this very counter productive,especially when you have deadlines.
In the end it was a good learning curve, that is till the next surprise.
We still need to link to the user assemblies to see if we can get the app size still smaller.

Thank you for commenting on this topic I appreciate it very much!
Started to think there is no support for Xamain Forms.

@jassmith
Copy link
Author

jassmith commented Apr 7, 2018

From @PureWeen on March 28, 2018 19:46

@ExzaSolutions have you tried with the latest Visual Studio? I've noticed in my case the latest updates seem to give a better exception than NRE and indicate exactly what it's unable to link

@jassmith
Copy link
Author

jassmith commented Apr 7, 2018

From @ExzaSolutions on March 28, 2018 19:50

Hi,thank you,I will give it a try.That will help a lot.

@jassmith
Copy link
Author

jassmith commented Apr 7, 2018

I am migrating this over to the android team :)

@jonpryor jonpryor added need-info Issues that need more information from the author. Area: Linker Issues when linking assemblies. labels Apr 10, 2018
@jonathanpeppers
Copy link
Member

@ExzaSolutions it's been a while since we've heard back on this. Can you send a repro?

Closing this for now, as we have had many releases since VS 15.5 (on VS 15.8.5 at present). Feel free to reopen and give more info if this is still a problem, thanks!

@rcunniffe
Copy link

@jonathanpeppers @jassmith did you ever get clear repo steps? I always set linking to none... as it just results in java errors.

@jonathanpeppers
Copy link
Member

@rcunniffe if you can reproduce this, can you file a new issue with your build logs? A sample project would be even better!

I have tested Xamarin.Forms apps with linking set to Full and LinkSdkOnly recently and it worked for me on VS 2017 15.8.x. So it could be something specific to your project?

@rcunniffe
Copy link

@jonathanpeppers in fairness a basic project from scratch will mostly always be ok. It's when you have a more complex project overtime with plugins ,signings and things like push notification permissions. Making it hard to track down these sorts of issues, but yeah if i get a chance to recreate, I will.

@ExzaSolutions
Copy link

Xamarin Forms seems to have large app file sizes,if you remove the linking it just gets too big to give to clients.

@rcunniffe
Copy link

@ExzaSolutions yep, of course you are right. But the point is people cannot compile when it's turned on. For myself, I have always gotten the same error message: 4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2464,3): error MSB6006: "java.exe" exited with code 1.

In the output I can see plenty of warnings but nothing that stands out as an error.

@ExzaSolutions
Copy link

Yes that is true,thank you!

@EmilAlipiev
Copy link

Search for error MSB6006: "java.exe" exited with code 1. There are several reason for it. We all have been there

@rcunniffe
Copy link

yeah agreed, ive update java, heapsize etc. Just it always seems to come up. normally down to proguard.

@yorkvolvo
Copy link

@jassmith @samhouts @jonathanpeppers, Hi team, this is York from Xamarin APAC support team, my customer encounter the same issue. Everything works fine last week, but when my customer updated all Xamarin.Android.Suppport.* nuget package from 26.0.2 to 27.0.2.1, the issue happened.

When android is set to build to Release,and the linking is set to Sdk Assemblies only, the issue happened:

4>  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly.
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018: Mono.Linker.MarkException: Error processing method: 'System.Boolean System.Buffers.BufferExtensions::SequenceEqual(System.Buffer`1<T>,System.Buffer`1<T>)' in assembly: 'System.Buffers.Primitives.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Boolean System.SpanExtensions::SequenceEqual(System.Span`1<!!0>,System.ReadOnlySpan`1<!!0>)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.ProcessQueue()
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    --- End of inner exception stack trace ---
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.ProcessQueue()
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.Process()
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at Mono.Linker.Pipeline.Process(LinkContext context)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at Xamarin.Android.Tasks.LinkAssemblies.Execute()
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2053,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

Customer has shared his issue project and I could reproduce this issue on my side, my VS version is 15.8.7. To protect my customer's privacy, I will share you with the issue project via email. If you have any problem, please feel free to contact me. :)

@jonathanpeppers
Copy link
Member

Hi, folks, submit a new issue if you're still seeing an issue related to this. We believe the NullReferenceException coming from LinkAssemblies is fixed, so it's likely something new.

I followed up with @aixiaozi over email, and the issue in the project (Mono.Linker.MarkException) was related to these three NuGet packages:

<package id="System.Binary" version="0.1.0-alpha-001" targetFramework="monoandroid80" />
<package id="System.Buffers.Primitives" version="0.1.0-alpha-001" targetFramework="monoandroid80" />
<package id="System.Collections.Sequences" version="0.1.0-alpha-001" targetFramework="monoandroid80" />

They weren't actually used, so removing them solved the problem.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: Linker Issues when linking assemblies. need-info Issues that need more information from the author.
Projects
None yet
Development

No branches or pull requests

8 participants