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.


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.+"
            }
        }
    }
}