6

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.

Sweta Jain
  • 3,248
  • 6
  • 30
  • 50

4 Answers4

6

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)

mliu
  • 1,708
  • 15
  • 26
0

please refer this question you will get to know reason behind it. This question is already asked in some form.

Understanding RecyclerView setHasFixedSize

Ankit Mishra
  • 530
  • 8
  • 16
0

This error is sheer nonsense, I think.

I just suppress it as method annotation:

@SuppressWarnings("InvalidSetHasFixedSize")

or as suppression comment like this:

//noinspection InvalidSetHasFixedSize
myRecyclerView.setHasFixedSize(true);

source

I don't see the point of resizing RecyclerViews to fit the content, and I know with absolute certainty that mine don't. It's almost insulting that Lint spits out these warnings (and as a "fatal error" no less).

The incredible Jan
  • 741
  • 10
  • 17
0

If you encounter the "linting error warning" while building a release APK, you can resolve it by modifying your app-level build.gradle file. Here's an improved version of the Stack Overflow answer that provides a clear explanation and includes the necessary changes:

If you receive a linting error warning during the release APK build process, this can be resolved by adjusting the configuration in your app-level build.gradle file. To fix this issue, follow these steps:

  1. Open your app-level build.gradle file.
  2. Locate the android block, which contains your existing code.
  3. Add the following lines within the android block:
android {
    // Your existing code here

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
    }

    lintOptions {
        checkReleaseBuilds false
    }
}

By adding these lines, you instruct the build system to exclude the 'META-INF/DEPENDENCIES' file from the packaging options. This helps to resolve the linting error warning you encountered during the release APK build process.

Make sure to sync your project after making these changes to apply them effectively.

MANISH
  • 2,883
  • 4
  • 11
  • 30