Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve symbol v7 : import android.support.v7.widget.RecyclerView

Tags:

android

gradle

I'm trying to import this : import android.support.v7.widget.RecyclerView;

But I got that : "Cannot resolve symbole v7".

Indeed, when I'm typing android.support. I can choose v4 but not v7

This is my build.gradle :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.bibstandardandroidstudio"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildToolsVersion '28.0.3'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0-alpha03'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha03'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'org.mindrot:jbcrypt:0.4'
    implementation 'com.android.volley:volley:1.1.1'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
}

I'm new to Android and I'm trying to follow this tutorial : Create a List with RecyclerView

I saw that implementation 'com.android.support:appcompat-v7:28.0.0' should unlock my situation but it don't seem to work

like image 568
Lotakz Avatar asked Jan 02 '23 02:01

Lotakz


2 Answers

Add the following dependency to use recylerview:

implementation 'com.android.support:recyclerview-v7:28.0.0'

or for Android X:

implementation 'androidx.recyclerview:recyclerview:1.0.0'

as specified in point 2 under "Add the support library" creating recylerview. You can use the recyclerview under androidx like so:

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
like image 188
Iain Avatar answered Jan 13 '23 11:01

Iain


The support library has got a new version and is no longer used. I also recommend to use AndroidX.

Click Refactor option in the android studio ribbon and choose Migrate to AndroidX. If you are new there then first create a copy of the project and then try AndroidX. Well, there is not much difference.

Then use the AndroidX recyclerview:

<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
like image 42
Gourav Avatar answered Jan 13 '23 10:01

Gourav