xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] Error processing method: 'System.Void AndroidX.Activity.ComponentActivity::.ctor #14989

Open gianisimone opened 2 years ago

gianisimone commented 2 years ago

Description

When I try to run my Xamarin Forms application in Release Mode for Android (Linker Behaviour: Link SDK Assemblies only), I get the following linker error:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Legacy.targets(5,5): Error XALNK7000: Mono.Linker.MarkException: Error processing method: 'System.Void AndroidX.Activity.ComponentActivity::.ctor(System.IntPtr,Android.Runtime.JniHandleOwnership)' in assembly: 'Xamarin.AndroidX.Activity.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve AndroidX.Core.View.IMenuHost
  at Mono.Linker.Steps.MarkStep.HandleUnresolvedType (Mono.Cecil.TypeReference reference) [0x00013] in <256050d9b61b4848876345a052636c75>:0 
  at Mono.Linker.Steps.MarkStep.MarkInterfaceImplementations (Mono.Cecil.TypeDefinition type) [0x00035] in <256050d9b61b4848876345a052636c75>:0 
  at Mono.Linker.Steps.MarkStep.MarkRequirementsForInstantiatedTypes (Mono.Cecil.TypeDefinition type) [0x0001b] in <256050d9b61b4848876345a052636c75>:0 
  at Mono.Linker.Steps.MarkStep.ProcessMethod (Mono.Cecil.MethodDefinition method) [0x00049] in <256050d9b61b4848876345a052636c75>:0 
  at Mono.Linker.Steps.MarkStep.ProcessQueue () [0x0001b] in <256050d9b61b4848876345a052636c75>:0 
   --- End of inner exception stack trace ---
  at Mono.Linker.Steps.MarkStep.ProcessQueue () [0x00047] in <256050d9b61b4848876345a052636c75>:0 
  at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue () [0x0000a] in <256050d9b61b4848876345a052636c75>:0 
  at Mono.Linker.Steps.MarkStep.Process () [0x000f6] in <256050d9b61b4848876345a052636c75>:0 
  at Mono.Linker.Steps.MarkStep.Process (Mono.Linker.LinkContext context) [0x0000d] in <256050d9b61b4848876345a052636c75>:0 
  at MonoDroid.Tuner.MonoDroidMarkStep.Process (Mono.Linker.LinkContext context) [0x0000b] in <256050d9b61b4848876345a052636c75>:0 
  at Mono.Linker.Pipeline.ProcessStep (Mono.Linker.LinkContext context, Mono.Linker.Steps.IStep step) [0x0000d] in <256050d9b61b4848876345a052636c75>:0 
  at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x0000f] in <256050d9b61b4848876345a052636c75>:0 
  at MonoDroid.Tuner.Linker.Run (Mono.Linker.Pipeline pipeline, Mono.Linker.LinkContext context) [0x00000] in <256050d9b61b4848876345a052636c75>:0 
  at MonoDroid.Tuner.Linker.Process (MonoDroid.Tuner.LinkerOptions options, Mono.Linker.ILogger logger, Mono.Linker.LinkContext& context) [0x00071] in <256050d9b61b4848876345a052636c75>:0 
  at Xamarin.Android.Tasks.LinkAssemblies.Execute (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver res) [0x0018f] in <256050d9b61b4848876345a052636c75>:0 
  at Xamarin.Android.Tasks.LinkAssemblies.RunTask () [0x0001b] in <256050d9b61b4848876345a052636c75>:0 
  at Microsoft.Android.Build.Tasks.AndroidTask.Execute () [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:17  (XALNK7000)

Expected Behavior

App runs properly

Actual Behavior

I got the error mentioned above

Basic Information

Environment

Show/Hide Visual Studio info ``` === Visual Studio Community 2019 for Mac === Version 8.10.16 (build 2) Installation UUID: 7d4807fc-4980-4cf1-9643-3e6a0af1e8e9 GTK+ 2.24.23 (Raleigh theme) Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638) Package version: 612000162 === Mono Framework MDK === Runtime: Mono 6.12.0.162 (2020-02/2ca650f1f62) (64-bit) Package version: 612000162 === Roslyn (Language Service) === 3.10.0-4.21269.26+029847714208ebe49668667c60ea5b0a294e0fcb === NuGet === Version: 5.9.0.7134 === .NET SDK (x64) === SDK: /usr/local/share/dotnet/sdk/5.0.404/Sdks SDK Versions: 5.0.404 5.0.403 5.0.402 5.0.401 5.0.400 5.0.302 5.0.301 5.0.203 5.0.202 5.0.201 5.0.103 3.1.416 3.1.415 3.1.414 3.1.413 3.1.412 3.1.411 3.1.410 3.1.409 3.1.408 3.1.407 3.1.406 MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks === .NET Core Runtime === Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 5.0.13 5.0.12 5.0.11 5.0.10 5.0.9 5.0.8 5.0.7 5.0.6 5.0.5 5.0.4 5.0.3 3.1.22 3.1.21 3.1.20 3.1.19 3.1.18 3.1.17 3.1.16 3.1.15 3.1.14 3.1.13 3.1.12 === .NET Core 3.1 SDK === SDK: 3.1.416 === .NET 5.0 SDK === SDK: 5.0.404 === Xamarin.Profiler === Version: 1.6.15.68 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler === Updater === Version: 11 === Apple Developer Tools === Xcode 13.1 (19466) Build 13A1030d === Xamarin.Mac === Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version. === Xamarin.iOS === Version: 15.4.0.0 (Visual Studio Community) Hash: 8fc41ae82 Branch: xcode13.2 Build date: 2021-12-09 01:07:56-0500 === Xamarin Designer === Version: 16.11.0.39 Hash: cd672761d Branch: remotes/origin/d16-11 Build date: 2021-10-06 21:09:18 UTC === Xamarin.Android === Version: 12.0.0.3 (Visual Studio Community) Commit: xamarin-android/d16-11/f0e3c2d Android SDK: /Users/simone/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: None installed SDK Tools Version: 26.1.1 SDK Platform Tools Version: 30.0.4 SDK Build Tools Version: 30.0.2 Build Information: Mono: c633fe9 Java.Interop: xamarin/java.interop/d16-11@476bb5b ProGuard: Guardsquare/proguard/v7.0.1@912d149 SQLite: xamarin/sqlite/3.35.4@85460d3 Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-11@87af37b === Eclipse Temurin JDK === Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home 1.8.0.302 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL === Android SDK Manager === Version: 16.10.0.13 Hash: 1b81df5 Branch: remotes/origin/d16-10 Build date: 2021-11-12 01:17:32 UTC === Android Device Manager === Version: 16.10.0.15 Hash: 89dcc0b Branch: remotes/origin/d16-10 Build date: 2021-11-12 01:17:52 UTC === Build Information === Release ID: 810160002 Git revision: 6dbc7886fa608147f685a7df3912249400c84716 Build date: 2021-12-14 15:54:37-05 Build branch: release-8.10 === Operating System === Mac OS X 11.6.0 Darwin 20.6.0 Darwin Kernel Version 20.6.0 Mon Aug 30 06:12:21 PDT 2021 root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64 ```

Build Logs

See error mentioned in the description

Workaround

The only thing that works for me is to change the Linker Behaviour to Don't Link, which it is not recommended for production builds

jfversluis commented 2 years ago

Looks like it's linked to #13969 there is a workaround in there, hopefully that works for you while we look at things :)

gianisimone commented 2 years ago

@jfversluis thank you. At the moment I solved building the app with Linker Behaviour set to Don't Link. Should I downgrade the AndroidX.Core to 1.3.2.1?

egette commented 2 years ago

@gianisimone Do you have a solution to this bug, except setting Linker Behaviour to Don't Link ?

gianisimone commented 2 years ago

@egette No unfortunately. My Xamarin Forms project is still suffering from this error. I did not manage to compile my Android solution with Linker Behaviour not set to Don't Link.

I keep my packages and Visual Studio updated but the issue is still there. I don't know how to solve this. I hope someone from Xamarin Forms team will take care of this very soon

amardhere commented 1 year ago

I also facing same issue. I have added all required references, but the error "Mono.Linker.MarkException" is still not resolving. It appears that there may be some compatibility issues with interlinked Xamarin libraries. This error occurs when upgrading Android version 13 and only in 'Release' mode, as there are no errors in debug mode. Linker value set as 'None' in the project property.

Error Mono.Linker.MarkException: Error processing method: 'System.Void AndroidX.Activity.ComponentActivity::.ctor(System.IntPtr,Android.Runtime.JniHandleOwnership)' in assembly: 'Xamarin.AndroidX.Activity.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve AndroidX.Core.App.IOnMultiWindowModeChangedProvider at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference) at Mono.Linker.Steps.MarkStep.MarkInterfaceImplementations(TypeDefinition type) at Mono.Linker.Steps.MarkStep.MarkRequirementsForInstantiatedTypes(TypeDefinition type) at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method) at Mono.Linker.Steps.MarkStep.ProcessQueue() --- End of inner exception stack trace --- at Mono.Linker.Steps.MarkStep.ProcessQueue() at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue() at Mono.Linker.Steps.MarkStep.Process() at Mono.Linker.Steps.MarkStep.Process(LinkContext context) at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context) at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step) at Mono.Linker.Pipeline.Process(LinkContext context) at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context) at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res) at Xamarin.Android.Tasks.LinkAssemblies.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17