java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/view/MenuHost;

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/view/MenuHost;

我正在我的应用程序中进行 google 登录。

每当我打开我的应用程序时,它就会崩溃并显示 NoClassDefFoundError

我检查了 logcat 并发现了这个:-

    --------- beginning of crash
2022-05-13 18:59:08.881 3810-3810/com.java.whatsapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.java.whatsapp, PID: 3810
    java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/view/MenuHost;
        at java.lang.Class.newInstance(Native Method)
        at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
        at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1244)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3183)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3410)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2017)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7397)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.view.MenuHost" on path: DexPathList[[zip file "/data/app/com.java.whatsapp-NhlLILW0268bo0W5tj1Gxw==/base.apk"],nativeLibraryDirectories=[/data/app/com.java.whatsapp-NhlLILW0268bo0W5tj1Gxw==/lib/arm64, /system/lib64, /system/product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at java.lang.Class.newInstance(Native Method) 
        at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95) 
        at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45) 
        at android.app.Instrumentation.newActivity(Instrumentation.java:1244) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3183) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3410) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2017) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7397) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935) 

这是build.gradle(module) :-

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 31
    buildToolsVersion "30.0.3"

    defaultConfig {
        configurations.all {
            resolutionStrategy {
                force 'androidx.core:core:1.6.0'
            }
        }
        applicationId "com.java.whatsapp"
        compileSdkVersion 31
        minSdkVersion 28
        targetSdkVersion 31
        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 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.6.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation 'com.google.android.gms:play-services-auth:20.2.0'
    implementation 'com.google.firebase:firebase-auth:21.0.4'
    implementation 'com.github.bumptech.glide:glide:4.11.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

为什么会出现这个错误? 请帮助我!

调试的时候发现了问题

问题在andoidx.appcompatclass没有找到

在应用程序中 build.gradle, 我更改了这行依赖项:

implementation 'androidx.appcompat:appcompat:1.4.1'

收件人:

implementation 'androidx.appcompat:appcompat:1.3.1'

可能是新版本改变了class路径。