Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Updating Xamarin.AndroidX.AppCompat to 1.6.0 causes ReflectionLoadException #15668

Closed
MagicAndre1981 opened this issue Jan 20, 2023 · 32 comments · Fixed by #15718
Closed
Labels
p/Android s/unverified New report that has yet to be verified t/bug 🐛

Comments

@MagicAndre1981
Copy link
Contributor

Description

Updating Xamarin.AndroidX.AppCompat to 1.6.0 causes following error at startup:

Could not resolve type with token 01000363 from typeref (expected class 'AndroidX.AppCompat.Graphics.Drawable.DrawableWrapper' in assembly 'Xamarin.AndroidX.AppCompat.AppCompatResources, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null')

Steps to Reproduce

  1. Update Xamarin.AndroidX.AppCompat to 1.6.0
  2. debug app

Expected Behavior

app starts fine

Actual Behavior

error at startup

Basic Information

Environment

VS2019 16.11.23

Workaround

stay at 1.5.1.1

@MagicAndre1981 MagicAndre1981 added s/unverified New report that has yet to be verified t/bug 🐛 labels Jan 20, 2023
@jfversluis
Copy link
Member

Usually this happens after an upgrade and you need to aggressively do some rebuilds and/or delete the bin & obj folders to clear the cache. Have you tried that?

@MagicAndre1981
Copy link
Contributor Author

yes, I did this. I just saw at AndroidX repository there is also a bug report similar to mine

@MagicAndre1981 MagicAndre1981 changed the title [Bug] Updating Xamarin.AndroidX.AppCompat to 1.6.0 causes TypeLoadException [Bug] Updating Xamarin.AndroidX.AppCompat to 1.6.0 causes ReflectionLoadException Jan 23, 2023
@MagicAndre1981
Copy link
Contributor Author

@jfversluis I also tested the new massive nuget updates from PR and issue is the same.

Comparing 1.5.1.1 with 1.6.x shows that the classes are renamed. In 1.6.x Compat was added to class names in AndroidX.AppCompat.AppCompatResource.

_Appcompat

This is why DrawableWrapper is not found any longer as the new name is now DrawableWrapperCompat

@MagicAndre1981
Copy link
Contributor Author

The Android Platform implements ClipDrawableWrapper in ShellSearchView.cs from DrawableWrapper.

And because of the renamed class this causes runtime failure. So update this code and require new lib as nuget dependency

@sk1llsh0t
Copy link

I'm getting this same error as well.

@MagicAndre1981
Copy link
Contributor Author

as mentioned above a class is renamed and XF requires the old class name which triggers this error.

@sk1llsh0t
Copy link

It is strange the error only occurs for me when i've set the deployment configuration to release. if it is set to debug, it works.

@MagicAndre1981
Copy link
Contributor Author

ok @jfversluis those new AndroidX nugets require now Targetframework 12.0 . This is a massive change in code. Can someone from the team make retarget and nuget androidx bumps?

@solomonfried
Copy link

I am targeting Android 12 and still can't build in Release. I have switched back to 1.5.1.1 for the Xamarin.AndroidX.AppCompat and Xamarin.AndroidX.AppCompat.AppCompatResources.
Seems to be working

@MagicAndre1981
Copy link
Contributor Author

Android 12 is required for building XF with new androidx nugets not your app itself.

@solomonfried
Copy link

@MagicAndre1981 Not sure I understand. I am building on VS2022 with Android SDK Platform 33 installed.
My Target Android Version for the app is 12.0 API Level 31

Release build fails with Failed to resolve AndroidX.AppCompat.Graphics.Drawable.DrawableWrapper using AppCompat Nuget libraries 1.6.x. But does build with 1.5.1.1

@MagicAndre1981
Copy link
Contributor Author

yes, but trying to make XF comaptible with AndroidX.AppCompat.Graphics.Drawable.DrawableWrapper 1.6.x XF itself must target Android12. Currently they build XF against old AndroidX libs and target Android10

@solomonfried
Copy link

Got it! So we need to wait for an update. I'll stay on 15.1.1 until we get the XF update

Thanks for the clarification.

@sasa-bobic
Copy link

A workaround that so far works for me was to build a custom binding library and add missing (renamed) classes back and repacking this in custom local nuget.

Basically this:
https://github.com/sasa-bobic/Xamarin.AndroidX.AppCompat.AppCompatResources/blob/master/Xamarin.AndroidX.AppCompat.AppCompatResources/Additions/DrawableContainer.cs)

And this:
https://github.com/sasa-bobic/Xamarin.AndroidX.AppCompat.AppCompatResources/blob/master/Xamarin.AndroidX.AppCompat.AppCompatResources/Additions/DrawableWrapper.cs

See this repo:
https://github.com/sasa-bobic/Xamarin.AndroidX.AppCompat.AppCompatResources

@donfbecker
Copy link

Downgrading to 1.5.1.1 does not solve the problem for me. I have tried clearing all caches after downgrade, but problem persists.

@rvalitov
Copy link

@donfbecker it worked for me. Perhaps you have some nuget packages that have dependency of the ver 1.6.0 of AppCompat and silently selected newer version to be installed?

@donfbecker
Copy link

@donfbecker it worked for me. Perhaps you have some nuget packages that have dependency of the ver 1.6.0 of AppCompat and silently selected newer version to be installed?

The NuGet package manager reported that 1.5.1.1 was installed, but I did find some warnings about version requirements of other Xamarin.AndroidX packages that were in use. I had to downgrade the other four AndroidX packages as well.

@cncb-gh
Copy link

cncb-gh commented Apr 10, 2023

Will this be addressed soon or do we all need to use the workaround @sasa-bobic posted?

@MagicAndre1981
Copy link
Contributor Author

there is a PR to fix the issue and upgrade to Monodroid13.0

@AlleSchonWeg
Copy link
Contributor

Same problem in release mode. Debug works. Problem is that Xamarin.AndroidX.AppCompat >= 1.6.0 is needed for the new "per-app language preferences" in android 13: https://developer.android.com/guide/topics/resources/app-languages#java

@takaz-ams
Copy link

takaz-ams commented Apr 13, 2023

@sasa-bobic followed that and updated package then the error changed. Now getting this: Type androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat$1 is defined multiple times

Error in obj\Release\130\lp\132\jl\classes.jar:androidx/appcompat/graphics/drawable/AnimatedStateListDrawableCompat$1.class:
Type androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat$1 is defined multiple times: obj\Release\130\lp\132\jl\classes.jar:androidx/appcompat/graphics/drawable/AnimatedStateListDrawableCompat$1.class, obj\Release\130\lp\26\jl\bin\classes.jar:androidx/appcompat/graphics/drawable/AnimatedStateListDrawableCompat$1.class
Compilation failed
java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj\Release\130\lp\132\jl\classes.jar
androidx/appcompat/graphics/drawable/AnimatedStateListDrawableCompat$1.class
at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:98)
at com.android.tools.r8.D8.main(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:4)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj\Release\130\lp\132\jl\classes.jar:androidx/appcompat/graphics/drawable/AnimatedStateListDrawableCompat$1.class
at Version.fakeStackEntry(Version_3.3.75.java:0)
at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:75)
at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:28)
at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:27)
at com.android.tools.r8.internal.Fj.b(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:2)
at com.android.tools.r8.D8.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:22)
at com.android.tools.r8.D8.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:17)
at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:85)
... 1 more
Caused by: com.android.tools.r8.internal.f: Type androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat$1 is defined multiple times: obj\Release\130\lp\132\jl\classes.jar:androidx/appcompat/graphics/drawable/AnimatedStateListDrawableCompat$1.class, obj\Release\130\lp\26\jl\bin\classes.jar:androidx/appcompat/graphics/drawable/AnimatedStateListDrawableCompat$1.class
at com.android.tools.r8.internal.JT.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:14)
at com.android.tools.r8.internal.JT.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:22)
at com.android.tools.r8.internal.HN.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:26)
at com.android.tools.r8.internal.HN.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:10)
at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2048)
at com.android.tools.r8.internal.HN.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:6)
at com.android.tools.r8.graph.B2$a.e(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:4)
at com.android.tools.r8.dex.b.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:110)
at com.android.tools.r8.dex.b.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:28)
at com.android.tools.r8.D8.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:25)
at com.android.tools.r8.D8.d(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:606)
at com.android.tools.r8.D8.c(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:1)
at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:24)
... 5 more
Directory 'obj\Release\130\lp\132' is from 'androidx.appcompat.appcompat-resources.aar'

@KRA2008
Copy link

KRA2008 commented Apr 13, 2023

I’m also very interested in a fix for this, but in the meantime the workaround that I found to be easiest was simply to downgrade the Xamarin.AndroidX.AppCompat versions to 1.5.1.1 and then also (by consequence) to target Android 12 rather than 13. This workaround will continue to work for publishing apps to Google Play until the store starts requiring targeting 13 in August of 2023.

@siddhant-maurya
Copy link

I am also facing the same error, and our project needs to be updated to Android 13. Can anyone provide a solution please!

@MagicAndre1981
Copy link
Contributor Author

as said, Microsoft works on it and already has a PR

@BillyMartin1964
Copy link

Xamarin.AndroidX.AppCompat

It's not that it works in debug. It works with Linker set to none.

@ivaldiviah
Copy link

Downgrading Xamarin.AndroidX.AppCompat to 1.5.1.1 does not solve the problem, clean the proyect and delete bin and obj folder does not solve the problem...

In Debug mode, works perfectly, the problem is only in release mode, i have de links options to none and persist de error.

Has anyone found any solution?

@mos379
Copy link

mos379 commented May 29, 2023

@ivaldiviah just use pre release of xamarin.forms and latest appCompat. then it should work.

@dejanbasic
Copy link

dejanbasic commented Jun 7, 2023

It works for me, when I also downgrade Xamarin.AndroidX.AppCompat.AppCompatResources to 1.5.1.1

https://stackoverflow.com/a/76185857

@pulmuone
Copy link

@MagicAndre1981
Copy link
Contributor Author

Thank you. I solved it with this content.

why? Simply use the official XF SR15

@pulmuone
Copy link

Thank you. I solved it with this content.

why? Simply use the official XF SR15

Maui (.net7) Android AOT Compile Error.
dotnet/android#8252 (comment)

@MagicAndre1981
Copy link
Contributor Author

ok, this topic is about Xamarin Forms, so it was not clear that you use MAUI

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p/Android s/unverified New report that has yet to be verified t/bug 🐛
Projects
None yet
Development

Successfully merging a pull request may close this issue.