Android Studio报错:cannot resolve symbol recyclerview

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),如下

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.spacesoftwares.openglesdemo"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

其中加了一句,

   implementation 'com.android.support:recyclerview-v7:27.1.1'

然后执行sync,一切OK。

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

猜你喜欢

转载自blog.csdn.net/tanmx219/article/details/81413699