震惊:新建android项目竟然报错,Rejecting re-init on previously-failed...

错误提示

03-20 14:54:57.718 7909-7909/? I/zygote64: Rejecting re-init on previously-failed class java.lang.Class: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
03-20 14:54:57.719 7909-7909/? I/zygote64:     at void android.support.v4.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2341)
        at void android.support.v7.widget.ActionBarContainer.(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:62)
        at java.lang.Object java.lang.reflect.Constructor.newInstance0(java.lang.Object[]) (Constructor.java:-2)
        at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:334)
        at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:651)
        at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:794)
        at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:734)
        at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:867)
        at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:828)
        at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:519)
        at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:427)
        at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:374)
        at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:607)
        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 com.example.kingnewspring.kotlintest.MainActivity.onCreate(android.os.Bundle) (MainActivity.kt:24)
        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/com.example.kingnewspring.kotlintest-f-pJtef5aNEspOp1AQerjw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.kingnewspring.kotlintest-f-pJtef5aNEspOp1AQerjw==/lib/arm64, /system/lib64, /system/vendor/lib64]]
        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.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2341)
        at void android.support.v7.widget.ActionBarContainer.(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:62)
        at java.lang.Object java.lang.reflect.Constructor.newInstance0(java.lang.Object[]) (Constructor.java:-2)
        at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:334)
        at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:651)
        at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:794)
        at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:734)
        at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:867)
        at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:828)
        at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:519)
        at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:427)
        at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:374)
        at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:607)
        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 com.example.kingnewspring.kotlintest.MainActivity.onCreate(android.os.Bundle) (MainActivity.kt:24)
        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)

错误场景

直接新建一个android项目,全部默认配置,运行后提示错误,但是错误并不会影响使用,也不会导致闪退,因此错误级别不是很高,甚至可以不处理,但是有点强迫症的我还是决定把它解决掉

错误分析

直接看错误码第一句

 Rejecting re-init on previously-failed class java.lang.Class: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;

提示类找不到错误:java.lang.NoClassDefFoundError,并且指明是这个类
android/view/View$OnUnhandledKeyEventListener,于是我们根据目录找到这个接口:

震惊:新建android项目竟然报错,Rejecting re-init on previously-failed..._第1张图片
android View类.png

图中左上角看到一排提示,提示没有 api 28的资源! 我看了下,我android SDK的确没有安装 api 28,但是我的编译版本却是 api28,虽然这不是问题的根本原因(即使你安装了安卓9.0即 api28的sdk也是报错),但是却提醒了我,可能是运行时平台的原因,而我debug的手机系统是 api 27,要比编译版本低!!:
震惊:新建android项目竟然报错,Rejecting re-init on previously-failed..._第2张图片
app下的build.gradle文件.png

至此,知道问题的解决方案了

解决方案

  • 将依赖平台改成模拟器或真机对应的平台,我的手机是api27,注意依赖也需要改
    震惊:新建android项目竟然报错,Rejecting re-init on previously-failed..._第3张图片
    修改后.png

再次debug,控制台没有再次报错了!秉着求证的精神,我全局搜索了下刚刚报错找不到的接口,发现在api27平台的确找不到

震惊:新建android项目竟然报错,Rejecting re-init on previously-failed..._第4张图片
搜不到该类.png

看来该接口的确是 api 28开始加上去的。

总结

编译版本不能乱用,需谨慎。不是什么大问题,仅当给强迫症的朋友,一个解决问题的思路。

你可能感兴趣的:(震惊:新建android项目竟然报错,Rejecting re-init on previously-failed...)