android - 无法解析导入android.support.v7.widget.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 中的错误报告:
解决方案
您正在尝试访问错误的包。
尝试 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 选项进行自动修复
推荐阅读
- microsoft-dynamics - AX 2012 R3 AIF 自定义 Web 服务
- html - 当我添加 HTML 或 CSS 时,为什么我的网站是空白的?
- c# - 在 ASP.NET Core MVC 中捕获 HandleUnauthorizedRequest
- sql-server - 使用 oracle 目的地从 sql server 到 oracle 的数据传输
- python - Tensorflow Image Classification Tutorial, crash on the second epoch
- javascript - 如何在按钮上方显示切换选项卡
- highcharts - 我们可以为时间线栏设置颜色吗?
- abap - BASE CORRESPONDING 需要哪个 Netweaver 版本?
- c++ - 从 for 循环中获取地图中的上一个或下一个项目
- javascript - 传单地图实时路线跟踪