android studio: Rejecting re-init on previously-failed class java.lang.Class: java.lang.NoClassDefFoundError: Failed resolution o

时间:2022-07-22 18:14:32

今天在运行部署项目时logcat弹出下列错误:

-- ::46.481 -/? E/Zygote: v2
-- ::46.481 -/? I/libpersona: KNOX_SDCARD checking this for
-- ::46.481 -/? I/libpersona: KNOX_SDCARD not a persona
-- ::46.482 -/? E/Zygote: accessInfo :
-- ::46.482 -/? W/SELinux: SELinux selinux_android_compute_policy_index : Policy Index[], Con:u:r:zygote:s0 RAM:SEPF_SECMOBILE_7.0_0010, [- - - - ]
-- ::46.483 -/? I/SELinux: SELinux: seapp_context_lookup: seinfo=untrusted, level=s0:c512,c768, pkgname=com.yongdaimi.android.ffapitest
-- ::46.486 -/? I/art: Late-enabling -Xcheck:jni
-- ::46.564 -/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
-- ::46.587 -/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;
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.support.v4.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at java.lang.Object java.lang.reflect.Constructor.newInstance0!(java.lang.Object[]) (Constructor.java:-)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:)
-- ::46.587 -/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:)
-- ::46.587 -/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:)
-- ::46.587 -/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:)
-- ::46.587 -/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:)
-- ::46.587 -/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:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void com.yongdaimi.android.ffapitest.MatrixDemoActivity.onCreate(android.os.Bundle) (MatrixDemoActivity.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:)
-- ::46.587 -/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:-)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.os.Looper.loop() (Looper.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:)
-- ::46.587 -/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]]
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.support.v4.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at java.lang.Object java.lang.reflect.Constructor.newInstance0!(java.lang.Object[]) (Constructor.java:-)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:)
-- ::46.587 -/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:)
-- ::46.587 -/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:)
-- ::46.587 -/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:)
-- ::46.587 -/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:)
-- ::46.587 -/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:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.support.v7.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void com.yongdaimi.android.ffapitest.MatrixDemoActivity.onCreate(android.os.Bundle) (MatrixDemoActivity.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:)
-- ::46.587 -/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:-)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.os.Looper.loop() (Looper.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:)
-- ::46.587 -/com.yongdaimi.android.ffapitest I/art: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:)
-- ::46.629 -/com.yongdaimi.android.ffapitest W/Activity: AppLock checkAppLockState locked:false verifying:false pkgName = com.yongdaimi.android.ffapitest isInMultiWindowMode:false
-- ::46.658 -/com.yongdaimi.android.ffapitest I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus
-- ::46.674 -/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库的版本就好:

android studio: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>: java.lang.NoClassDefFoundError: Failed resolution o

实际实验了一下,确实是有效的。

这里还是要吐嘈下Google,虽说近几代的Android Studio有了不少的改进,但是平时使用下来还是有不少的缺陷,尤其是当项目代码量增加,模块增多了之后,编译时间巨慢,经常动不动在编译的时候会报一些莫名其妙的问题,但是clean或者是重启下AS就又好了,严重影响开发者的时间,相比之下微软的VS和苹果的XCode就很少有这种问题。我的AS经常是发生了一个错误,然后就提示我要不要发送问题到Google,个人也做过一段时间iOS的开发,对比之下觉得苹果真的是强,从软件生态,应用商店,开发工具,API,从上到下通通秒杀安卓,安卓想要超越苹果,恐怕还有很长的路要走。