'Linking error when trying to build Xamarin.Android project
I am trying to build my Xamarin.Android project. Initially I had set Linking to Sdk and User Assemblies. This configuration was not giving any errors, but it removed some commands from my app, so following this answer I switched the setting to Sdk assemblies only.
Unfortunately, this causes the following error:
Mono.Linker.MarkException: Error processing method: 'System.Void Plugin.FirebaseAnalytics.FirebaseAnalytics::SetMinimumSessionDuration(System.Int64)' in assembly: 'Plugin.FirebaseAnalytics.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void Firebase.Analytics.FirebaseAnalytics::SetMinimumSessionDuration(System.Int64)
at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
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()
--- 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/builder/azdo/_work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17
Since choosing Sdk and Users Assemblies probably is not an option, any idea how can I prevent the error that appears with Sdk assemblies only?
Solution 1:[1]
You will see this exception at runtime when code has been stripped from the executable usually by the linker or R8/Proguard. You can provide a custom link configuration file to both tools allowing you to keep code the linker or R8/Proguard you are not using. These tools are not able to properly detect code you use at runtime (e.g. via reflection) .
For this problem, you can drive the linking process with an XML file that describes what you want from the linker.
To do this, you define an XML file with the top-level element which contains assembly nodes which in turn contain type nodes, which in turn contain method and field nodes.
Once you have this linker description file, add it to your project and:
- For Android : set the Build Action to
LinkDescription - For iOS : set the Build Action to
LinkDescription
For more, you can check document: https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/linker
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jessie Zhang -MSFT |
