【问题标题】:Cannot resolve import android.support.v7.widget.RecyclerView; [duplicate]无法解析导入android.support.v7.widget.RecyclerView; [复制]
【发布时间】:2019-11-25 22:14:27
【问题描述】:

我需要在 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 中的错误报告:

【问题讨论】:

  • 张贴你的logcat而不是截图
  • 你有一半的喷气背包和一半的 appcompat。

标签: android android-studio android-recyclerview


【解决方案1】:

用这个替换你的 recyclerview 库 -> androidx.recyclerview:recyclerview:1.0.0 当您使用 androidx 时,但您的回收站视图的库仍处于支持库格式

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

【讨论】:

    【解决方案2】:

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

    尝试使用 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 选项进行自动修复

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多