Home » Java » android studio – java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener-Exceptionshub

android studio – java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I’m triying to running an android-tv application.
The application has heritage of FragmentActivity and his WebView is from a local library.

The application throws this exception when I’m click in any point of the view.

  • compileSdkVersion 29
  • minSdkVersion 19
  • targetSdkVersion 29

I tried this options:

  • Clean project.
  • Invalidate Caches /Restart
  • Change the targetSdkVersion and compileSdkVersion
  • This code in build.gradle:
configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == "androidx") {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion "${targetSdk}.+"
            }
        }
    }
}

The Exception:

I/zygote: Do partial code cache collection, code=26KB, data=30KB
I/zygote: After code cache collection, code=26KB, data=30KB
    Increasing code cache capacity to 128KB
I/zygote: 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;
        at boolean androidx.core.view.ViewCompat.dispatchUnhandledKeyEventBeforeHierarchy(android.view.View, android.view.KeyEvent) (ViewCompat.java:3802)
        at boolean androidx.core.view.KeyEventDispatcher.dispatchBeforeHierarchy(android.view.View, android.view.KeyEvent) (KeyEventDispatcher.java:63)
        at boolean androidx.core.app.ComponentActivity.dispatchKeyEvent(android.view.KeyEvent) (ComponentActivity.java:137)
        at boolean com.android.internal.policy.DecorView.dispatchKeyEvent(android.view.KeyEvent) (DecorView.java:354)
        at int android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(android.view.ViewRootImpl$QueuedInputEvent) (ViewRootImpl.java:4733)
        at int android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(android.view.ViewRootImpl$QueuedInputEvent) (ViewRootImpl.java:4605)
        at void 

The App build.gradle:

    apply plugin: 'com.android.application'

    apply plugin: 'kotlin-android'

    apply plugin: 'kotlin-android-extensions'

    android {
        compileSdkVersion 29
        buildToolsVersion "29.0.2"
        defaultConfig {
            applicationId "com.example.app-tv"
            minSdkVersion 19
            targetSdkVersion 29
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation project(':sibbowebview')
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        implementation 'androidx.leanback:leanback:1.0.0'
        implementation 'androidx.appcompat:appcompat:1.1.0'
        implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
        implementation 'com.google.code.gson:gson:2.8.6'
    }

The WebView build.gradle:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'consumer-rules.pro'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.leanback:leanback:1.0.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.facebook.stetho:stetho:1.5.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
How to&Answers: