java - 如何修复 Android Studio 中的“无法解析符号“v7”错误
问题描述
我正在尝试使用 android support recyclerView 小部件,虽然我已将所有依赖项添加到我的 build.gradle 文件中(我认为),但行“import android.support.v7.widget.RecyclerView;” 在我的活动中没有解决。我是 Android Studio 的新手,所以我可能会遗漏一些非常基本的东西。
到目前为止,我已经尝试在项目构建 gradle 的所有项目以及我的模块构建 gradle 的所有项目中添加 google 存储库。我也改变了我的依赖关系并尝试更改版本号。我尝试使缓存无效并重新启动。我似乎确实能够导入“import androidx.recyclerview.widget.RecyclerView;”,但这与我所听到的不一样。
这是我的构建 gradle 文件:
//noinspection GradleCompatible
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.example.chaos"
minSdkVersion 20
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
customDebugType {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:design:28.0.0'
//implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
androidTestImplementation 'android.arch.persistence.room:testing:1.1.1'
// implementation 'com.android.support:support-v7'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
androidTestImplementation ('androidx.test.espresso:espresso-core:3.2.0-alpha02', {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
然后这是我在主要活动中尝试的导入。看来我可以导入 android.support.v4 库,但 v7 甚至不是自动完成选项。我会很感激帮助!
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
我希望导入行能够解决,因为它目前没有。
解决方案
如果您使用的是 Android X,请尝试使用此依赖项
implementation 'androidx.recyclerview:recyclerview:1.0.0'
推荐阅读
- php - 获取 JSON 对象时出错“尝试获取非对象的属性”
- amazon-web-services - Beanstalk .ebextensions 错误 - 模板的资源块中未解决的资源依赖关系
- javascript - 我正在使用 vuetify 获得一个 v-on 处理程序 handler.apply 不是 vue 工具栏中的函数错误
- javascript - 需要很好的例子:templateShareable=true 什么时候有用?
- hibernate - Hibernate 版本列名异常
- ruby-on-rails - 在 Rails 中下载和重定向
- linux - libs 路径“/run/opengl-driver”如何注入到像 compton 这样的 Nix 二进制文件中
- typescript - 无法将参数传递给“forEach”
- nginx - 如何让nginx代理通过读取主机域映射
- three.js - MTLLoader 破坏了其他 3js 代码并且没有正确加载纹理