error: package RecyclerView does not exist

Viewed 367

While trying to build my repo I am running into following error:

MyAdapter.java:XY: error: package RecyclerView does not exist
static class MyViewHolder extends RecyclerView.ViewHolder

I am building with:

  • Gradle 6.7
  • on MacOS Catalina 10.15.7
  • Android target SDK 30
  • AndroidStudio 4.1.1

Gradle is configured for AndroidX:
android.useAndroidX=true
android.enableJetifier=true

I can see in project navigation of AndroidStudio that the dependency was downloaded and I can navigate the editor inside the class RecyclerView.ViewHolder.
Also important to mention that my repo can be build w/o any issues on a Windows machine. Repo contains several modules which have also classes that extends RecyclerView.ViewHolder but only this module fails to build on MacOS.
It seems that Gradle have different build process order in comparison to Gradle on Windows.

What I have tried:

  • rm -rf ~/.gradle/caches
  • ./gradlew cleanBuildCaches
  • re-installation of Android SDK
  • re-installation of Android Studio
  • excluded transitive dependency androidx.recyclerview:recyclerview in libs by adding exclude group: 'androidx.recyclerview', module: 'recyclerview'

Does anybody had a similar issue or can give any suggestion to resolve this issue?

1 Answers

My colleagues using MacOS fixed this by adding an additional static import

import static androidx.recyclerview.widget.RecyclerView.ViewHolder;

and changing

static class PageViewHolder extends RecyclerView.ViewHolder

to

static class PageViewHolder extends ViewHolder

Works fine now on MacOS and Windows.

Related