Search code examples
androidandroid-recyclerviewleanback

Can't access HorizontalGridView and RecyclerView


Why can't I use the HorizontalGridView and RecyclerView classes? Both these imports fail:

import android.support.v17.leanback.widget.HorizontalGridView;
import android.support.v7.widget.RecyclerView

The first because v17 cannot be resolved and the second RecyclerView cannot be resolved.

My SDK Root contains leanback-v17:

{sdk root}\sdk\extras\android\m2repository\com\android\support\leanback-v17

and I always keep up to date but still I can't access these classes because I can't import them. Even setting my min SDK to 22 doesn't help. Why?

Setup

Android Studio Build: 2.3.3, AI-162.4069837, 20170606,

AI-162.4069837, JRE 1.8.0_112-release-b06x64 JetBrains s.r.o, OS Windows 10(amd64) v10.0 , screens 1920x1080, 1920x1080


Solution

  • Add the following to your app/build.gradle file:

    // ...
    dependencies {
      compile 'com.android.support:leanback-v17:25.4.0'
      compile 'com.android.support:recyclerview-v7:25.4.0'
      // ...
    }
    

    You forgot the specify those dependencies.