question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compiler Issue with AndroidX.RecyclerView

See original GitHub issue

Xamarin.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

  1. Download the reproducible project from here (all assembly references and NuGet packages are installed).
  2. Make sure project in Release configuration and the Android project is set as Startup

Run 1 - Control Test

  1. Set LinkerBehavior to None
  2. Rebuild Solution (to restore NuGet packages and complete 1st build)
  3. => Observe a successful build

Run 2 - Reproducible Test

  1. Set LinkerBehavior to SDK Assemblies Only
  2. Clean project and Rebuild
  3. => 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:

  1. The class imports android.support.v7.widget.RecyclerView
  2. 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:closed
  • Created 4 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
BjornVanslembrouckcommented, Mar 2, 2020

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.)

    <PackageReference Include="Xamarin.Android.Support.Annotations">
      <Version>28.0.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.Collections">
      <Version>28.0.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.VersionedParcelable">
      <Version>28.0.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Arch.Core.Common">
      <Version>1.1.1.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Arch.Lifecycle.Common">
      <Version>1.1.1.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.Compat">
      <Version>28.0.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Arch.Lifecycle.ViewModel">
      <Version>1.1.1.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.Loader">
      <Version>28.0.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.Core.Utils">
      <Version>28.0.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.Core.UI">
      <Version>28.0.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.Fragment">
      <Version>28.0.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.v7.AppCompat">
      <Version>28.0.0.3</Version>
    </PackageReference>

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.

1reaction
LanceMcCarthycommented, Feb 26, 2020

Confirmed as a fix here, too. Thanks folks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is the RecyclerView not working when the compiler ...
if the data is present its means there is a problem with Recyclerview View, means data is good to go but recylerview is...
Read more >
Recyclerview | Jetpack
This table lists all the artifacts in the androidx.recyclerview group. ... Please take a look at the existing issues in this library before...
Read more >
RecyclerView creates dependencies problem
I was able to fix the problem by changing in my build.gradle file: compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
Read more >
Kotlin compiler pre-release problem in android studio IDE
I'm having problems with the project in Android Studio. I get a error message ... recycler: 'androidx.recyclerview:recyclerview:1.0.0-rc01', ...
Read more >
Android resource compilation failed error while upgrading ...
Hello, I have followed the step to upgrade the Meeting SDK android, but still receiving error AAPT: error: duplicate value for resource ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found