当前位置: 代码迷 >> 综合 >> java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener
  详细解决方案

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener

热度:37   发布时间:2023-09-28 23:09:26.0

最近后台封装的类库使用的v7包版本都使用了28的,导致我的项目也必须改为28,问题来了

implementation 'com.android.support:appcompat-v7:28.0.0'

改为28之后报错

 Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;at void android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, android.support.v4.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)at void android.support.v7.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)at void android.support.v7.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)at void cn.sagacloud.scanbuilding.activities.StartActivity.onCreate(android.os.Bundle) (StartActivity.kt:38)at void android.app.Activity.performCreate(android.os.Bundle, android.os.PersistableBundle) (Activity.java:7098)at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:7089)at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1215)at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2770)at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2895)at void android.app.ActivityThread.-wrap11(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1616)at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)at void android.os.Looper.loop() (Looper.java:173)at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6653)at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:547)at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:821)Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/cn.sagacloud.scanbuilding-qCs7ToQsposBFC0QEvdOAA==/base.apk", zip file "/data/app/cn.sagacloud.scanbuilding-qCs7ToQsposBFC0QEvdOAA==/split_lib_dependencies_apk.apk", zip file "/data/app/cn.sagacloud.scanbuilding-qCs7ToQsposBFC0QEvdOAA==/split_lib_slice_0_apk.apk", zip file "/data/app/cn.sagacloud.scanbuilding-qCs7ToQsposBFC0QEvdOAA==/split_lib_slice_1_apk.apk", zip file "/data/app/cn.sagacloud.scanbuilding-qCs7ToQsposBFC0QEvdOAA==/split_lib_slice_2_apk.apk", zip file "/data/app/cn.sagacloud.scanbuilding-qCs7ToQsposBFC0QEvdOAA==/split_lib_slice_3_apk.apk", zip file "/data/app/cn.sagacloud.scanbuilding-qCs7ToQsposBFC0QEvdOAA==/split_lib_slice_4_apk.apk", zip file "/data/app/cn.sagacloud.scanbuilding-qCs7ToQsposBFC0QEvdOAA==/split_lib_slice_5_apk.apk", zip file "/data/app/cn.sagacloud.scanbuilding-qCs7ToQsposBFC0QEvdOAA==/split_lib_slice_6_apk.apk", zip file "/
03-07 14:45:43.479 9783-9783/cn.sagacloud.scanbuilding I/zygote:     at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:125)at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)at void android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, android.support.v4.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)at void android.support.v7.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)at void android.support.v7.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)at void cn.sagacloud.scanbuilding.activities.StartActivity.onCreate(android.os.Bundle) (StartActivity.kt:38)at void android.app.Activity.performCreate(android.os.Bundle, android.os.PersistableBundle) (Activity.java:7098)at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:7089)at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1215)at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2770)at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2895)at void android.app.ActivityThread.-wrap11(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1616)at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)at void android.os.Looper.loop() (Looper.java:173)at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6653)at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:547)at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:821)Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;at void android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View, android.support.v4.view.OnApplyWindowInsetsListener) (ViewCompat.java:2203)at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:637)at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)at void android.support.v7.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)at void android.support.v7.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)at void cn.sagacloud.scanbuilding.activities.StartActivity.onCreate(android.os.Bundle) (StartActivity.kt:38)at void android.app.Activity.performCreate(android.os.Bundle, android.os.PersistableBundle) (Activity.java:7098)at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:7089)at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1215)at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2770)at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2895)at void android.app.ActivityThread.-wrap11(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1616)at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)at void android.os.Looper.loop() (Looper.java:173)at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6653)at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:547)at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:821)

有人说包v7 包的版本改回27 或26 ,在我这里行不通,改了之后会导致后台封装的类库无法使用所有这个行不通只能另想办法了

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

上面的代码添加到 build.gradle 下面就可以了

dependencies {implementation fileTree(include: ['*.jar'], dir: 'libs')androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {exclude group: 'com.android.support', module: 'support-annotations'})//noinspection GradleDependency,GradleCompatibleimplementation 'com.android.support:appcompat-v7:28.0.0'implementation "com.android.support:design:28.0.0"configurations.all {resolutionStrategy.eachDependency { DependencyResolveDetails details ->def requested = details.requestedif (requested.group == 'com.android.support') {if (!requested.name.startsWith("multidex")) {details.useVersion '27.+'}}}}}

暂时解决了这个问你,如果你有好的办法,请留言…

  相关解决方案