android studio: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution o
======================================== 2021/1/21更新 =================================================
最近改用 androidx 了,结果还是有这个问题。。。
找到app 模块下的build.gradle文件,将:
androidx.appcompat:appcompat:1.2.0 替换成: androidx.appcompat:appcompat:1.3.0-alpha02
然后Gradle 重新sync一下就好了,我现在用的AS版本是4.1.2,新建项目部署时仍然有这个问题,不过换成上面那个版本的appcompat库,瞬间世界清净了。
======================================== 2021/1/21更新 =================================================
今天在运行部署项目时logcat弹出下列错误:
2019-04-26 13:57:46.481 27346-27346/? E/Zygote: v2 2019-04-26 13:57:46.481 27346-27346/? I/libpersona: KNOX_SDCARD checking this for 10421 2019-04-26 13:57:46.481 27346-27346/? I/libpersona: KNOX_SDCARD not a persona 2019-04-26 13:57:46.482 27346-27346/? E/Zygote: accessInfo : 0 2019-04-26 13:57:46.482 27346-27346/? W/SELinux: SELinux selinux_android_compute_policy_index : Policy Index[2], Con:u:r:zygote:s0 RAM:SEPF_SECMOBILE_7.0_0010, [-1 -1 -1 -1 0 1] 2019-04-26 13:57:46.483 27346-27346/? I/SELinux: SELinux: seapp_context_lookup: seinfo=untrusted, level=s0:c512,c768, pkgname=com.yongdaimi.android.ffapitest 2019-04-26 13:57:46.486 27346-27346/? I/art: Late-enabling -Xcheck:jni 2019-04-26 13:57:46.564 27346-27346/com.yongdaimi.android.ffapitest W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: 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; 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.support.v4.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2341) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:62) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at java.lang.Object java.lang.reflect.Constructor.newInstance0!(java.lang.Object[]) (Constructor.java:-2) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:430) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:652) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:794) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:734) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:865) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:828) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:525) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:427) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:378) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:607) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void com.yongdaimi.android.ffapitest.MatrixDemoActivity.onCreate(android.os.Bundle) (MatrixDemoActivity.java:30) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6942) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1126) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2880) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2988) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.app.ActivityThread.-wrap14(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1631) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.os.Looper.loop() (Looper.java:154) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6682) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:1520) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:1410) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.yongdaimi.android.ffapitest-1/base.apk"],nativeLibraryDirectories=[/data/app/com.yongdaimi.android.ffapitest-1/lib/arm, /data/app/com.yongdaimi.android.ffapitest-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]] 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.support.v4.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2341) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:62) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at java.lang.Object java.lang.reflect.Constructor.newInstance0!(java.lang.Object[]) (Constructor.java:-2) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:430) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:652) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:794) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:734) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:865) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:828) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:525) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:427) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:378) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:607) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void com.yongdaimi.android.ffapitest.MatrixDemoActivity.onCreate(android.os.Bundle) (MatrixDemoActivity.java:30) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6942) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1126) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2880) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2988) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.app.ActivityThread.-wrap14(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1631) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.os.Looper.loop() (Looper.java:154) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6682) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:1520) 2019-04-26 13:57:46.587 27346-27346/com.yongdaimi.android.ffapitest I/art: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:1410) 2019-04-26 13:57:46.629 27346-27346/com.yongdaimi.android.ffapitest W/Activity: AppLock checkAppLockState locked:false verifying:false pkgName = com.yongdaimi.android.ffapitest isInMultiWindowMode:false 2019-04-26 13:57:46.658 27346-27346/com.yongdaimi.android.ffapitest I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus 2019-04-26 13:57:46.674 27346-27363/com.yongdaimi.android.ffapitest I/OpenGLRenderer: Initialized EGL, version 1.4
这个错误不会影响项目正常运行,但是每次项目跑起来就提示一次,真的烦人,个人平时对于logcat打印的错误日志还是很重视的,决定查看下这到底是什么问题。仔细看了下报错的位置,是在:
setContentView(R.layout.activity_matrix_demo);
这一行,可问题是这只有一行代码呀,而且布局文件很简单,根本就不可能出错:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/bt_change_color" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="变换" /> <!--<ImageView android:id="@+id/iv_display" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/ic_yangmi" />--> </LinearLayout>
万般无奈,只能求助万能的Google,后来发现有人也跟我遇到过同样的问题:https://blog.csdn.net/weixin_37651459/article/details/80956366 ,按照他的说法是Android SDK Tools的版本与Appcompat库的版本不对应所致,更改下项目下的build.gradle中的Appcompat库的版本就好:
实际实验了一下,确实是有效的。
这里还是要吐嘈下Google,虽说近几代的Android Studio有了不少的改进,但是平时使用下来还是有不少的缺陷,尤其是当项目代码量增加,模块增多了之后,编译时间巨慢,经常动不动在编译的时候会报一些莫名其妙的问题,但是clean或者是重启下AS就又好了,严重影响开发者的时间,相比之下微软的VS和苹果的XCode就很少有这种问题。我的AS经常是发生了一个错误,然后就提示我要不要发送问题到Google,个人也做过一段时间iOS的开发,对比之下觉得苹果真的是强,从软件生态,应用商店,开发工具,API,从上到下通通秒杀安卓,安卓想要超越苹果,恐怕还有很长的路要走。
androidx.appcompat:appcompat:1.3.0-alpha02