簡體   English   中英

如何修復 Android Studio 中的“無法解析符號“v7”錯誤

[英]How to fix 'Cannot Resolve Symbol 'v7' error in Android Studio

我正在嘗試使用 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;

我希望導入行能夠解決,因為目前還沒有。

如果您使用的是 Android X,請嘗試使用此依賴項

implementation 'androidx.recyclerview:recyclerview:1.0.0'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM