首页 > 解决方案 > 无法将 CoordinatorLayout 与 AndroidX 一起使用

问题描述

我正在尝试使用CoordinatorLayoutwithAndroidx但我有这个错误

The following classes could not be found: androidx.coordinatorlayout.widget.CoordinatorLayout

我不知道为什么我会得到这个错误,尽管我把它的依赖。

我也尝试更改版本,androidx.appcompat但也遇到了同样的错误

构建.Gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
    applicationId "com.example.bitprojecttask"
    minSdkVersion 15
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
  }

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.cardview:cardview:1.0.0"

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

//recycler view
implementation 'androidx.recyclerview:recyclerview:1.1.0'
//retrofit
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0"
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
//OKHTTP3 library
implementation "com.squareup.okhttp3:okhttp:3.11.0"
implementation "com.squareup.okhttp3:okhttp-urlconnection:3.11.0"
implementation "com.squareup.okhttp3:logging-interceptor:3.11.0"
//import json
implementation 'com.google.code.gson:gson:2.8.2'
//Butterknife
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'

implementation 'de.hdodenhof:circleimageview:3.0.0'

implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'

}

标签: javaandroidandroidx

解决方案


您错过了为 Android 设计支持库添加材料

implementation 'com.google.android.material:material:1.0.0'

推荐阅读