无法解析导入android.support.v7.widget.RecyclerView;

时间:2019-07-17 06:28:32

标签: android android-studio android-recyclerview

我需要在Android Studio中创建一个recyclerview。我不知道为什么它一直说不能解决符号recyclerview。我已经按照那些网站教程完成了所有步骤。

我的应用gradle文件:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 17
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.firebase:firebase-core:17.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.android.support:appcompat-v7:29.1.1'
    //card view
    implementation 'com.android.support:cardview-v7:29.1.1'
    //recyclerView
    implementation 'com.android.support:recyclerview-v7:29.1.1'
    //picasso library to retrive images
    implementation 'com.squareup.picasso:picasso:2.71828'


    implementation 'com.google.firebase:firebase-storage:18.0.0'

    implementation 'com.google.firebase:firebase-auth:18.0.0'
    implementation 'com.google.firebase:firebase-database:18.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    apply plugin: 'com.google.gms.google-services'

}

我可以知道gradle文件中的代码怎么了吗?提前致谢。 这是我在logcat中的错误报告:

error

2 个答案:

答案 0 :(得分:1)

您正在尝试访问错误的软件包。

尝试androidx.recyclerview而不是旧版android.support.v7.widget.RecyclerView;

您应该替换所有com.android.support。*依赖项,并替换为androidx等效项。 (当前,您混合使用了androidx和旧版android.support依赖项)

https://developer.android.com/jetpack/androidx/releases/recyclerview

您可以尝试使用Android Studio上的Refactor> Migrate to AndroidX选项进行自动修复

enter image description here

答案 1 :(得分:0)

用-> androidx.recyclerview:recyclerview:1.0.0替换您的recyclerview库 因为您使用的是androidx,但是您的回收者视图的库仍为支持库格式

要获取正确的迁移信息,请参考此-> https://developer.android.com/jetpack/androidx/migrate

相关问题