即使在gradle中添加了依赖项,“也无法解析类android.support.v4.widget.DrawerLayout”

时间:2020-10-16 12:11:50

标签: android android-support-library androidx drawerlayout

即使在build.gradle文件中同时添加了DrawerLayout Cannot resolve class android.support.v4.widget.DrawerLayout和Material androidx.drawerlayout:drawerlayout:1.1.1实现之后,我仍然遇到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' */
}

2 个答案:

答案 0 :(得分:2)

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

应为import androidx.drawerlayout.widget.DrawerLayout

答案 1 :(得分:2)

检查支持库和androidx库之间的类mapping

android.support.v4.widget.DrawerLayout ->   androidx.drawerlayout.widget.DrawerLayout

在布局和代码androidx.drawerlayout.widget.DrawerLayout中使用。

相关问题