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

Mono.Cecil.ResolutionException: Failed to resolve AndroidX.AppCompat.Graphics.Drawable.DrawableWrapper #690

Closed
CtrlAltDeleteMeNot opened this issue Jan 19, 2023 · 27 comments

Comments

@CtrlAltDeleteMeNot
Copy link

Android application type

Classic Xamarin.Android (MonoAndroid12.0, etc.)

Affected platform version

VS 2022

Description

Ran migration to AndroidX, and application no longer compiles.
Dependencies here:

<ItemGroup>
    <PackageReference Include="Huawei.Agconnect.AgconnectCore">
      <Version>1.5.0.301</Version>
    </PackageReference>
    <PackageReference Include="Huawei.Hms.Push">
      <Version>6.3.0.304</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.CodeAnalysis.Analyzers">
      <Version>3.3.4</Version>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Xam.Plugin.Geolocator">
      <Version>4.5.0.6</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.v7.AppCompat">
      <Version>28.0.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Legacy.Support.Core.Utils">
      <Version>1.0.0.15</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.AppCompat">
      <Version>1.6.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.RecyclerView">
      <Version>1.2.1.8</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Activity">
      <Version>1.6.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.AppCompat.AppCompatResources">
      <Version>1.6.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Biometric">
      <Version>1.1.0.11</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Common">
      <Version>120.2.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Iid">
      <Version>121.1.0.7</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Messaging">
      <Version>123.1.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Forms" Version="5.0.0.2545" />
    <PackageReference Include="Xamarin.Essentials" Version="1.7.4" />
    <PackageReference Include="Xamarin.GooglePlayServices.Base">
      <Version>118.1.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.GooglePlayServices.Basement">
      <Version>118.1.0.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.GooglePlayServices.Gcm">
      <Version>117.0.0.7</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.GooglePlayServices.Tasks">
      <Version>118.0.2</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Migration" Version="1.0.10" />
  </ItemGroup>

Error here:

Mono.Linker.MarkException: Error processing method: 'System.Void Xamarin.Forms.Platform.Android.ShellSearchView/ClipDrawableWrapper::.ctor(Android.Graphics.Drawables.Drawable)' in assembly: 'Xamarin.Forms.Platform.Android.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve AndroidX.AppCompat.Graphics.Drawable.DrawableWrapper
   at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference)
   at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
   at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
   at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
   at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
   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	XXXXXXXXX.Android			

Relevant log output

C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000: Mono.Linker.MarkException: Error processing method: 'System.Void Xamarin.Forms.Platform.Android.ShellSearchView/ClipDrawableWrapper::.ctor(Android.Graphics.Drawables.Drawable)' in assembly: 'Xamarin.Forms.Platform.Android.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve AndroidX.AppCompat.Graphics.Drawable.DrawableWrapper
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference)
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.ProcessQueue()
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    --- End of inner exception stack trace ---
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.ProcessQueue()
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.Process()
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at Mono.Linker.Pipeline.Process(LinkContext context)
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    at Xamarin.Android.Tasks.LinkAssemblies.RunTask()
8>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(648,5): error XALNK7000:    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
@CtrlAltDeleteMeNot
Copy link
Author

I have also attached a minimalist example to showcase the issue.
Minimal.zip

@MagicAndre1981
Copy link

I got the same, some classes are renamed in 1.6 compared to 1.5.1.1

@sk1llsh0t
Copy link

i'm getting the same error

@cncb-gh
Copy link

cncb-gh commented Jan 23, 2023

Me too, but downgrading to 1.5.1.1 does not seem to fix it.

@sk1llsh0t
Copy link

It works in debug but when i change to release and run, that is when the error occurs.

@BrianSouza
Copy link

Me too, the same problem. I try downgrading to 1.5.1.1 but i still having this problem.

@jrariasf
Copy link

jrariasf commented Feb 1, 2023

The same to me. I can Build in Debug mode but when I choose Release then it fails:

Severity Code Description Project File Line Suppression State
Error Mono.Linker.MarkException: Error processing method: 'System.Void Xamarin.Forms.Platform.Android.ShellSearchView/ClipDrawableWrapper::.ctor(Android.Graphics.Drawables.Drawable)' in assembly: 'Xamarin.Forms.Platform.Android.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve AndroidX.AppCompat.Graphics.Drawable.DrawableWrapper
at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference)
at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
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 YPA.Android

@guardianrol
Copy link

Hello, i have the same problem. In Debug mode the app compile correctly, but the Release mode, show this error. Somebody solution this error?

@sk1llsh0t
Copy link

sk1llsh0t commented Feb 1, 2023

One "workaround" is to go into the android project properties -> Build -> Android -> Linker and set Linker Behavior to "Don't Link" (I'm working on VS for Mac). Obviously this isn't a solution but at least gets past the error.

I tried adding the problematic assembly to the "Ignore assemblies" box that is having the issue but I couldn't get that to work. I've used this setting in the past when there's been other problematic assemblies similar to this issue

@cncb-gh
Copy link

cncb-gh commented Feb 1, 2023

One "workaround" is to go into the android project properties -> Build -> Android -> Linker and set Linker Behavior to "Don't Link" (I'm working on VS for Mac). Obviously this isn't a solution but at least gets past the error.

What are the side effects of this?

I hope someone is looking into this because I am unable to update my app in the store. Android forced me to update the target api which forced me to update Xamarin.AndroidX.AppCompat which will not allow me to build a release version. Frustrating.

@sk1llsh0t
Copy link

It'll make it bloated. the linker strips out unused objects. so if you don't strip anything out, your apk will contain everything under the sun in it.

@jrariasf
Copy link

jrariasf commented Feb 2, 2023

As commented above, the workaround for me has been also to configure "None" in "Linking".
I use VS 2022 on Windows10, so go into android project properties, then "Android Options" and set "Linking" to "None".
Thanks!

PD: In the Android.csproj will appear a line like this:
<AndroidLinkMode>None</AndroidLinkMode>

@MagicAndre1981
Copy link

compiling works fine in debug, but the (XamarinForms) app simple crashes when you try to run it. In my linked issue you can see that classes in the AndroidX update got renamed and XF needs an update.

For those where it worked, do you use a pur Xamarin.Android app and NO forms?

@sk1llsh0t
Copy link

My app is a xamarin forms app.

@MagicAndre1981
Copy link

MagicAndre1981 commented Feb 2, 2023

I have no idea why not linking should fix it as the classes are renamed:

_Appcompat

and in XF the Android Platform implements ClipDrawableWrapper in ShellSearchView.cs from DrawableWrapper and as the class is renamed you get the error at runtime

@jpobst
Copy link
Contributor

jpobst commented Feb 2, 2023

Looking at the decompiled Java, Google did in fact rename these classes in 1.6.0:

1.5.1

image

1.6.0

image

Note that while turning off linking may let your application compile, it will not allow it to run. It will likely crash when XF tries to use this class.

Reference: https://android.googlesource.com/platform/frameworks/support/+/de70044326e54d6a50f0745f481bd46927cb777a

@cncb-gh
Copy link

cncb-gh commented Feb 9, 2023

Note that while turning off linking may let your application compile, it will not allow it to run. It will likely crash when XF tries to use this class.

To be clear, it will crash even if not using that class directly from the app (Xamarin forms might use it internally)?

@MagicAndre1981
Copy link

yes, XF uses it internally

@jpobst
Copy link
Contributor

jpobst commented Feb 14, 2023

Closing, as there is nothing else to be done for this in this repository.

The issue is tracked in the Xamarin.Forms repository: xamarin/Xamarin.Forms#15668.

@jpobst jpobst closed this as completed Feb 14, 2023
@pablo-mendoza
Copy link

pablo-mendoza commented Feb 24, 2023

Does anybody got this fixed? I can't build my app even by downgrading

@MagicAndre1981
Copy link

other AndroidX libs now depend on AppCompat 1.6.x, so make sure you use the latest version that depend on 1.5.1.x

@AmrAlSayed0
Copy link

@jpobst Just a thought, could there be a breaking change check that would maybe stop the publishing of such nuget packages until the .NET net guidelines for deprecating and removing a class is followed? Something like providing a class with the old name that inherits from the new class but it's marked as obsolete for some time until it's safe to remove it. I know this is manual work to be done in this repo when you're clearly trying to automate the entire process but class renames and removals should be rare and I think .NET nuget packages should follow .NET guidelines even if Google doesn't.

@jpobst
Copy link
Contributor

jpobst commented Feb 24, 2023

Unfortunately we maintain roughly ~500 Android packages that are constantly being updated, so doing anything manually is largely out of the question.

I think a longer term solution that may help is dotnet/java-interop#1081. Even though these API (and others) are "public", Google considers them "internal" and therefore does not feel the need to maintain API compatibility.

If this information was surfaced to C# consumers, they would be aware of the risk and would hopefully choose "safer" API to use. I suspect for this particular case, the Xamarin.Forms team had no idea this API was not considered "public", "stable" API.

@jrariasf
Copy link

Hi,
have you try to do what I wrote days ago? Something about configure "None" in "Linking".
I would like to know if this workaround is ok (for me is ok because I have been able to build in Debug and Release mode).
Please, tell me.
Good luck!

@MagicAndre1981
Copy link

again, google renamed classes in AndroidX lib, and even if the app compiles, it crashes at runtime

@cncb-gh
Copy link

cncb-gh commented Mar 27, 2023

Is this particular instance/error going to be fixed manually before a generic fix is determined? I have not been able to build for months now, and I don't want to release something more than twice as big as before with possible unexpected crashes.

@jpobst
Copy link
Contributor

jpobst commented Mar 27, 2023

As mentioned above, this is a Xamarin.Forms issue that is tracked here:
xamarin/Xamarin.Forms#15668

@xamarin xamarin locked as resolved and limited conversation to collaborators Mar 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants