Android Studio报错:cannot resolve symbol recyclerview

短命女 2022-05-17 01:45 295阅读 0赞

Android Studio真是什么奇葩报错都有,今天建了个新项目,居然无缘无故出现:cannot resolve symbol recyclerview。自动提示中也没有RecyclerView,在java中导入包,

import android.support.v7.widget.RecyclerView;

也没有作用,还是不认。到stackover上找了一下,

https://stackoverflow.com/questions/39619788/recyclerview-cannot-resolve-symbol-errors-android-studio

根据上面的说法,更新了build.gradle(app),如下

  1. apply plugin: 'com.android.application'
  2. android {
  3. compileSdkVersion 27
  4. defaultConfig {
  5. applicationId "com.spacesoftwares.openglesdemo"
  6. minSdkVersion 21
  7. targetSdkVersion 27
  8. versionCode 1
  9. versionName "1.0"
  10. testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  11. }
  12. buildTypes {
  13. release {
  14. minifyEnabled false
  15. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  16. }
  17. }
  18. }
  19. dependencies {
  20. implementation fileTree(dir: 'libs', include: ['*.jar'])
  21. implementation 'com.android.support:appcompat-v7:27.1.1'
  22. implementation 'com.android.support.constraint:constraint-layout:1.1.2'
  23. implementation 'com.android.support:recyclerview-v7:27.1.1'
  24. testImplementation 'junit:junit:4.12'
  25. androidTestImplementation 'com.android.support.test:runner:1.0.2'
  26. androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
  27. }

其中加了一句,

implementation ‘com.android.support:recyclerview-v7:27.1.1’

然后执行sync,一切OK。

我看了一下以前的项目,在这个build.gradle中都没有加这一 句,也都能成功编译,没有任何问题。不知道为什么现在需要加这么一句,因此猜测可能是后来装了某些插件导致。

发表评论

表情:
评论列表 (有 0 条评论,295人围观)

还没有评论,来说两句吧...

相关阅读