"Cannot resolve class android.support.v4.widget.DrawerLayout" 即使在 gradle 中添加依赖项之后
"Cannot resolve class android.support.v4.widget.DrawerLayout" even after adding dependencies in gradle
即使在我的 build.gradle 文件中添加了 DrawerLayout androidx.drawerlayout:drawerlayout:1.1.1
和 Material com.google.android.material:material:1.0.0
实现后,我仍然收到 Cannot resolve class android.support.v4.widget.DrawerLayout
错误。
我已经尝试添加其他实现,例如 com.android.support:support-compat:28.0.0
和 com.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
应该是导入androidx.drawerlayout.widget.DrawerLayout
检查支持库和androidx库之间的class mapping:
android.support.v4.widget.DrawerLayout -> androidx.drawerlayout.widget.DrawerLayout
在您的布局和代码中使用 androidx.drawerlayout.widget.DrawerLayout
。
即使在我的 build.gradle 文件中添加了 DrawerLayout androidx.drawerlayout:drawerlayout:1.1.1
和 Material com.google.android.material:material:1.0.0
实现后,我仍然收到 Cannot resolve class android.support.v4.widget.DrawerLayout
错误。
我已经尝试添加其他实现,例如 com.android.support:support-compat:28.0.0
和 com.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
应该是导入androidx.drawerlayout.widget.DrawerLayout
检查支持库和androidx库之间的class mapping:
android.support.v4.widget.DrawerLayout -> androidx.drawerlayout.widget.DrawerLayout
在您的布局和代码中使用 androidx.drawerlayout.widget.DrawerLayout
。