How to resolve NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;

Sometimes after an upgrade, you need to invalidate and clear cache.

enter image description here

There are some known issues in 3.2 so also ensure you are not on Kotlin tools org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.70

as that causes freeze issues as well. If that doesn't work, remove your google plugin lines and support libraries, sync and add them again and sync. Sometimes the cache directories just get out of whack.


I solved a similar issue

Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
 
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener"

Adding dependency in build.gradle (app level)

implementation 'androidx.core:core:1.5.0-alpha04'

if you are using android x try this (add this code segment to app level Gradle file)

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    def requested = details.requested
    if (requested.group == "androidx") {
        if (!requested.name.startsWith("multidex")) {
            details.useVersion "${targetSdk}.+"
        }
    }
}}

if you are not using android x try this code segment.

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    def requested = details.requested
    if (requested.group == "com.android.support") {
        if (!requested.name.startsWith("multidex")) {
            details.useVersion "26.+"
        }
    }
}}

Got similar issue with androidx dependencies as like

Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;

Resolved by adding configurations in Gradle files as below

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == "androidx.appcompat") {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion "1.+"
            }
        }
    }
}

Add this to gradle will resolve the issue, works for me:

implementation 'androidx.appcompat:appcompat:1.3.0-alpha02'

Please note 1.2.0 even doesn't work