【问题标题】:How to fix 'Cannot Resolve Symbol 'v7' error in Android Studio如何修复 Android Studio 中的“无法解析符号“v7”错误
【发布时间】:2019-03-28 14:16:38
【问题描述】:

我正在尝试使用 android 支持 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;

我希望导入行能够解决,因为它目前没有。

【问题讨论】:

  • 您应该检查几件事,grafle 构建是否同步?而且大多数情况下,你不能将 androidx 与支持结合起来,你必须选择
  • 正如cutiko所说,这可能是android x问题。再次重构到 AndroidX,如果问题仍然存在,则使缓存无效。
  • 有没有办法收回我对 AndroidX 的使用? gradle 构建确实是同步的 :)

标签: java android android-recyclerview


【解决方案1】:

如果您使用的是 Android X,请尝试使用此依赖项

implementation 'androidx.recyclerview:recyclerview:1.0.0'

【讨论】:

  • 有没有办法让我不再使用 AndroidX?还是这是个坏主意?
  • 创建项目时,您可以取消选中 AndroidX 选项。但是,我不建议这样做。旧的支持库将不再更新。从现在开始只有 AndroidX。
猜你喜欢
  • 2019-09-07
  • 1970-01-01
  • 2019-07-29
  • 1970-01-01
  • 1970-01-01
  • 2015-03-03
  • 1970-01-01
  • 2015-03-03
  • 2017-12-10
相关资源
最近更新 更多