Search code examples
androidvisual-studioxamarin.formslinker-errorsvisual-studio-mac

Xamarin.AndroidX build error in release mode


I have a Xamarin Forms project for iOS and Android. The iOS app builds in both Debug and Release, but the Android app is not building in Release mode. I can build and run it in Debug fine, but I get the following error when I try to archive it for publishing in Visual Studio for Mac.

Mono.Linker.LoadException: Error while processing references of 'MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Xamarin.AndroidX.Work.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Xamarin.AndroidX.Work.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
  at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters parameters) [0x000ff] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/cecil/Mono.Cecil/BaseAssemblyResolver.cs:172 
  at Mono.Linker.AssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters parameters) [0x0008d] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 
  at Mono.Linker.LinkContext.Resolve (Mono.Cecil.IMetadataScope scope) [0x00007] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 
   --- End of inner exception stack trace ---
  at Mono.Linker.LinkContext.Resolve (Mono.Cecil.IMetadataScope scope) [0x00030] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 
  at Mono.Linker.LinkContext.ResolveReferences (Mono.Cecil.AssemblyDefinition assembly) [0x00026] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 
  at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences (Mono.Cecil.AssemblyDefinition assembly) [0x00026] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 
  at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences (Mono.Cecil.AssemblyDefinition assembly) [0x0003b] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 
   --- End of inner exception stack trace ---
  at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences (Mono.Cecil.AssemblyDefinition assembly) [0x0005b] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 
  at Mono.Linker.Steps.LoadReferencesStep.ProcessAssembly (Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 
  at Mono.Linker.Steps.BaseStep.Process (Mono.Linker.LinkContext context) [0x00025] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 
  at Mono.Linker.Pipeline.ProcessStep (Mono.Linker.LinkContext context, Mono.Linker.Steps.IStep step) [0x0000d] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 
  at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x0000f] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 
  at MonoDroid.Tuner.Linker.Run (Mono.Linker.Pipeline pipeline, Mono.Linker.LinkContext context) [0x00000] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 
  at MonoDroid.Tuner.Linker.Process (MonoDroid.Tuner.LinkerOptions options, Mono.Linker.ILogger logger, Mono.Linker.LinkContext& context) [0x00071] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 
  at Xamarin.Android.Tasks.LinkAssemblies.Execute (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver res) [0x001dd] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 
  at Xamarin.Android.Tasks.LinkAssemblies.RunTask () [0x0001b] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 
  at Xamarin.Android.Tasks.AndroidTask.Execute () [0x00000] in <4f0a19c9d0ec417f9e44b588fd30d062>:0 

Originally I had the Android app targeting Android 9 Oreo (API Version 28), but when I uploaded it to the Google Play store I received the following error:

Upload failed
Your app currently targets API level 27 and must target at least API level 28 to ensure it is built on the latest APIs optimized for security and performance. Change your app's target API level to at least 28.

So, I tried setting the target version to Android 10 (API Version 29), but then I got a deprecation error so I changed the target version back to 9 (API Version 28) and now I can't build in Release mode because of the above error.

Here are my Android app settings:

Android Manifest

Android General Settings

Android Build Settings


Solution

  • I ended up deleting everything in the bin and obj folders for the projects in the solution, restarted Visual Studio and was able to both build and archive the Android app and also didn't get the error message from Google Play. The wrong version of a library must have gotten cached.