无法解析符号v7:导入android.support.v7.widget.RecyclerView

时间:2019-04-12 14:07:36

标签: android gradle

我正在尝试导入: import android.support.v7.widget.RecyclerView;

但是我明白了:“无法解析Symbole v7”。

实际上,当我输入android.support.时,我可以选择v4,但不能选择v7

这是我的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'
}

我是Android的新手,我正在尝试遵循本教程:Create a List with RecyclerView

我发现implementation 'com.android.support:appcompat-v7:28.0.0'应该可以解决我的问题,但似乎不起作用

2 个答案:

答案 0 :(得分:2)

添加以下依赖项以使用recylerview:

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

或对于Android X:

implementation 'androidx.recyclerview:recyclerview:1.0.0'

在第2点“添加支持库” creating recylerview下指定。  您可以像下面这样在androidx下使用recyclerview:

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

答案 1 :(得分:0)

支持库有一个新版本,不再使用。我也建议使用AndroidX。

单击android studio功能区中的“重构”选项,然后选择“迁移到AndroidX”。如果您是新手,请先创建项目的副本,然后尝试AndroidX。好吧,差别不大。

然后使用AndroidX recyclerview:

<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
相关问题