Compiler Issue with AndroidX.RecyclerView
See original GitHub issueXamarin.Android Version (eg: 6.0):
- Xamarin 16.4.000.311
- Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-5@9f4ed4b
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: fd9f379
Java.Interop: xamarin/java.interop/d16-4@c4e569f
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.28.0@46204c4
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-5@9f4ed4b
Operating System & Version (eg: Mac OSX 10.11):
- Windows 10 18363
- Visual Studio 16.4.5
Support Libraries Version (eg: 23.3.0):
- Xamarin.Android Support Libraries 28.0.0.3 (see repro project for details)
- Compile with:
Android 10 Q
- Target SDK:
29
- Min SDK:
15
Describe your Issue:
When a Xamarin.Forms component has a dependency on Android.Support.v7.RecyclerView
, the AndroidX RecyclerView type is used by accident when the project’s Linker is set to SDK Assemblies Only
This results in an a build error claiming the setHasStableIds
method cannot be resolved.
Steps to Reproduce (with link to sample solution if possible):
Setup
- Download the reproducible project from here (all assembly references and NuGet packages are installed).
- Make sure project in Release configuration and the Android project is set as Startup
Run 1 - Control Test
- Set LinkerBehavior to None
- Rebuild Solution (to restore NuGet packages and complete 1st build)
- => Observe a successful build
Run 2 - Reproducible Test
- Set LinkerBehavior to SDK Assemblies Only
- Clean project and Rebuild
- => Observe the error listed below.
Include any relevant Exception Stack traces, build logs, adb logs:
Error Mono.Linker.MarkException: Error processing method: 'System.Void Telerik.XamarinForms.DataControlsRenderer.Android.ItemsControlRenderer::OnElementAttached(Telerik.XamarinForms.DataControls.ItemsControl)' in assembly: 'Telerik.XamarinForms.DataControls.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void AndroidX.RecyclerView.Widget.RecyclerView/Adapter::set_HasStableIds(System.Boolean)
Telerik Code
The location that error is thrown in in our adapter class. I am unable to share the full source code, but I can still identify how we’re expecting the type to be android.support.v7.widget.RecyclerView
Notice the following:
- The class imports
android.support.v7.widget.RecyclerView
- The CTOR is expecting
setHasStableIds()
to be available in the SDK’s RecyclerView Adapter
import android.support.v7.widget.RecyclerView;
...
public abstract class ListViewAdapterBase extends RecyclerView.Adapter<ListViewHolder> {
...
public ListViewAdapterBase() {
[dedacted]
[dedacted]
[dedacted]
this.setHasStableIds(true);
}
...
}
Workaround Attempt
I tried to avoid this by telling the compiler to linkskip Xamarin.Android.Support.v7.RecyclerView
. However, it doesn’t work. Is there another assembly I can add to workaround the issue?
the only solution I could find was to uninstall Xamarin.AndroidX.RecyclerView
. Once it (and dependencies) were uninstalled, the build works when linking out SDK Assemblies.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (3 by maintainers)
I’ve heard back from the Telerik team (thanks @LanceMcCarthy for the quick reply) and I might have found a workaround that works for the moment and that might be helpful for other people that have the same issue.
After browsing through the structure of the v7.AppCompat package, I’v added the following NuGet packages manually and kept the AndroidX ones in there as well (for XF 4.5). They need to be added in the right order (which I can’t remember exactly, but it looks like the order below is correct.)
I’ve set the linker to “Links SDK Assemblies Only” and build everything in release.
Tested on Android 7.1 (emulator) and Android 10.0 (Pixel 4) and the build succeeds and the app installs on the phones.
I’ve pushed it through our CI/CD process and successfully made a beta release in both the stores.
Confirmed as a fix here, too. Thanks folks!