DevAhamed / MultiViewAdapter

Easily create complex recyclerview adapters in android
https://devahamed.github.io/MultiViewAdapter
Apache License 2.0
818 stars 148 forks source link

getCachedSpanIndex of GridLayoutManager is inaccessible in SpanSizeLookup class #95

Closed RahulBhavani closed 5 years ago

RahulBhavani commented 5 years ago

Trying to access protected method getCachedSpanIndex of GridLayoutManager from SpanSizeLookup class.

DevAhamed commented 5 years ago

Hi,

Thanks for reporting this issue. Can you specify whether this issue is a lint warning or a build failure? Also kindly specify the recyclerview library version.

RahulBhavani commented 5 years ago

Hi, I have implemented MultiViewAdapter library as a dependency using gradle(2.0.0-beta01). I am able to build and run the app. I am using AndroidX library:

implementation 'androidx.appcompat:appcompat:1.1.0-alpha03'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

So RecyclerView gets imported from androidx.recyclerview.widget.RecyclerView & so does GridLayoutManager androidx.recyclerview.widget.GridLayoutManager

I am facing problem when using SpanCount in GridLayoutManager for following code

GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 4);
adapter.setSpanCount(4);
layoutManager.setSpanSizeLookup(adapter.getSpanSizeLookup());

And in my HeaderItemBinder I have:

@Override 
  public int getSpanSize(int maxSpanCount) {
    return maxSpanCount;
  }

My app is crashing at below:

java.lang.IllegalAccessError: Method 'int androidx.recyclerview.widget.GridLayoutManager$SpanSizeLookup.getCachedSpanIndex(int, int)' is inaccessible to class 'androidx.appcompat.widget.SpanSizeLookup' (declaration of 'androidx.appcompat.widget.SpanSizeLookup' appears in /data/app/my-package-name-1/split_lib_dependencies_apk.apk)
    at androidx.appcompat.widget.SpanSizeLookup.getCachedSpanIndex(SpanSizeLookup.java:67)
    at androidx.appcompat.widget.SpanSizeLookup.getSpanGroupIndex(SpanSizeLookup.java:87)
    at androidx.recyclerview.widget.GridLayoutManager.getSpanGroupIndex(GridLayoutManager.java:452)
DevAhamed commented 5 years ago

Hi,

Thanks for the clarification. MultiViewAdapter v3 supports androidx versions. Can you switch to 3.x branch and use 3.0.0-beta01 version? This will solve your issue.

Here is 3.x branch link : https://github.com/DevAhamed/MultiViewAdapter/tree/3.x

Note : This is issue happens because jetifier transformed all the dependent classes, but moved this particular class (SpanSizeLookup) to wrong package. Not a fault on jetifier, but the offending class was made to an internal method public. I will try to avoid relying on this internal method once 2.x and 3.x becomes stable.

RahulBhavani commented 5 years ago

I will switch to 3.0 version and will update the comments. Thank you for your reply and thank you for creating this awesome library!

RahulBhavani commented 5 years ago

Hi,

After switching to 3.0 version, I confirm that it now supports Androidx. A big Thank you!