android - "Cannot resolve class android.support.v4.widget.DrawerLayout"即使在 gradle 中添加依赖项之后

标签 android android-support-library androidx drawerlayout

即使在添加了 DrawerLayout androidx.drawerlayout:drawerlayout:1.1.1 和我的 build.gradle 文件中的 Material com.google.android.material:material:1.0.0 实现。

我尝试添加其他实现,例如 com.android.support:support-compat:28.0.0com.android.support:design:25.0.0,但错误仍然存​​在,应用程序无法启动。

知道如何解决这个问题吗?

build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "edu.ktu.birthdaycalendar"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'org.jetbrains:annotations-java5:15.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.drawerlayout:drawerlayout:1.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    def room_version = "2.2.5"
    def lifecycle_version = "2.2.0"
    def arch_version = "2.1.0"
    implementation "androidx.room:room-runtime:$room_version"
    annotationProcessor "androidx.room:room-compiler:$room_version"

    // optional - RxJava support for Room
    implementation "androidx.room:room-rxjava2:$room_version"
    // optional - Guava support for Room, including Optional and ListenableFuture
    implementation "androidx.room:room-guava:$room_version"
    // optional - Test helpers
    testImplementation "androidx.room:room-testing:$room_version"

    //lifecycle
    implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
    annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
    androidTestImplementation "androidx.arch.core:core-testing:$arch_version"

    implementation "com.google.android.material:material:1.0.0"
    /*implementation "com.android.support:support-compat:28.0.0"
    implementation "com.android.support:design:25.0.0"

    implementation "com.android.support:appcompat-v7:27.1.1"
    implementation "com.android.support:support-v4:27.1.1"
    implementation "com.android.support:design:27.1.1"
    //implementation 'com.android.support.constraint:constraint-layout:1.1.0' */
}

最佳答案

您导入了错误版本的 DrawerLayout。 android.support.v4.widget.DrawerLayout

应该是import androidx.drawerlayout.widget.DrawerLayout

关于android - "Cannot resolve class android.support.v4.widget.DrawerLayout"即使在 gradle 中添加依赖项之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64388975/

相关文章:

android - 与服务提供商的通信失败 : Twitter

Android Studio 终端无法将 gradle 识别为命令

android - 如何使用支持库为屏幕内外的 android fragment 设置动画

android - TextInputLayout 提示重叠问题

android - Gradle构建因编译时错误而失败,而Android Studio IDE未显示此类错误

java - Android 中 user.sendEmailVerification() 上没有虚拟方法 sendEmailVerification() 异常

java - 如何从我的自定义适配器更新 ListView

android - 如何找到androidx.browser :browser version?

android - 当我开始使用来自回收器项目的共享元素进行转换时,出现内存泄漏

android - 错误: duplicate value for resource 'attr/orientation' with config '' . aapt.v2.Aapt2Exception:Android资源编译失败