在编译apk时日志打印中出现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;,但是程序正常运行,也没有崩溃。
异常信息:
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 void androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(android.view.View,
androidx.core.view.OnApplyWindowInsetsListener) (ViewCompat.java:2421)
at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor()
(AppCompatDelegateImpl.java:779)
at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor()
(AppCompatDelegateImpl.java:659)
at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int)
(AppCompatDelegateImpl.java:552)
at void androidx.appcompat.app.AppCompatActivity.setContentView(int)
(AppCompatActivity.java:161)
at void com.tyky.zonghexianshiping.MainActivity.onCreate(android.os.Bundle)
(MainActivity.java:48)
at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6709)
....
解决:
升级androidx.appcompat:appcompat依赖,该依赖让我们可以在平台的旧版 API 上访问新 API(很多都符合 Material Design 准则)
当前依赖:
implementation 'androidx.appcompat:appcompat:1.1.0'
升级依赖:
implementation 'androidx.appcompat:appcompat:1.3.0'