Fatal lint error: Why using recyclerView.setHasFixedSize(true) with wrap_content for size in scrolling direction gives fatal lint error?

Viewed 542

While trying to generate a signed APK for release. I found the following error.

enter image description here

This error occurred only after I updated my Android Studio to 4.1.3.

enter image description here

On inspection, I found that recyclerView.setHasFixedSize(true) if used with wrap_content for size in scrolling direction, gives fatal lint error. I have resolved it by removing that line in all activities but still, I need to know why is this error fatal now, there was no such error before the update.

2 Answers

The error is based on the RecyclerView's height, not the items inside. I noticed this error didn't show for any of my viewbinding RecyclerViews, but shows up for my findById recyclerviews, even when height is match_parent. It turns out lint is not that smart. If you have any RecyclerView in your project that uses wrap_content and has the same id as your other recyclerviews, lint gets confused and will complain, even if your other layouts all use match_parent in their RecyclerView.

My fix was to rename the id for one of my RecyclerView causing the problem (a recyclerview inside a dialog, so it's necessary to use wrap_content in there)

Related