拒绝对先前失败的类java.lang.Class <android.support.v4.view.viewcompat $ onunhandledkeyeventlistenerwrapper> supportLib = 28进行重新初始化

时间:2018-11-15 20:20:58

标签: android

当我切换到supportLibrary 28时,开始出现这种奇怪的logcat消息,而27.1.1上没有发生。我尝试了一个空的默认项目,结果完全一样。

问题很容易重现,

创建一个活动为空的新项目,并在除API28仿真器之外的仿真器上运行。它将在我的API21模拟器上给出该错误:

2018-11-15 22:00:55.563 9948-9948/? 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;
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.support.v4.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2341)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.support.v7.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:62)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at java.lang.Object java.lang.reflect.Constructor.newInstance0!(java.lang.Object[]) (Constructor.java:-2)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:430)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:645)
2018-11-15 22:00:55.563 9948-9948/? 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:787)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:727)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:858)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:821)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:518)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:426)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:377)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:607)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.support.v7.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.support.v7.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void com.example.myapplication.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:11)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6666)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1118)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2732)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2844)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1572)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:110)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.os.Looper.loop() (Looper.java:203)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6364)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:1063)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:924)
2018-11-15 22:00:55.563 9948-9948/? I/art: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.example.myapplication-2/base.apk", zip file "/data/app/com.example.myapplication-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.myapplication-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.myapplication-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.myapplication-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.myapplication-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.myapplication-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.myapplication-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.myapplication-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.myapplication-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.myapplication-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.myapplication-2/split_lib_slice_9_
2018-11-15 22:00:55.563 9948-9948/? I/art:     at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.support.v4.view.ViewCompat.setBackground(android.view.View, android.graphics.drawable.Drawable) (ViewCompat.java:2341)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.support.v7.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:62)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at java.lang.Object java.lang.reflect.Constructor.newInstance0!(java.lang.Object[]) (Constructor.java:-2)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:430)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:645)
2018-11-15 22:00:55.563 9948-9948/? 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:787)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:727)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:858)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:821)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:518)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:426)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:377)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at android.view.ViewGroup android.support.v7.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:607)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:518)
2018-11-15 22:00:55.563 9948-9948/? I/art:     at void android.support.v7.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:466)
2018-11-15 22:00:55.564 9948-9948/? I/art:     at void android.support.v7.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:140)
2018-11-15 22:00:55.564 9948-9948/? I/art:     at void com.example.myapplication.MainActivity.onCreate(android.os.Bundle) (MainActivity.java:11)
2018-11-15 22:00:55.564 9948-9948/? I/art:     at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6666)
2018-11-15 22:00:55.564 9948-9948/? I/art:     at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1118)
2018-11-15 22:00:55.564 9948-9948/? I/art:     at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2732)
2018-11-15 22:00:55.564 9948-9948/? I/art:     at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2844)
2018-11-15 22:00:55.564 9948-9948/? I/art:     at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
2018-11-15 22:00:55.564 9948-9948/? I/art:     at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1572)
2018-11-15 22:00:55.564 9948-9948/? I/art:     at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:110)
2018-11-15 22:00:55.564 9948-9948/? I/art:     at void android.os.Looper.loop() (Looper.java:203)
2018-11-15 22:00:55.564 9948-9948/? I/art:     at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6364)
2018-11-15 22:00:55.564 9948-9948/? I/art:     at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2018-11-15 22:00:55.564 9948-9948/? I/art:     at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:1063)
2018-11-15 22:00:55.564 9948-9948/? I/art:     at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:924)

我的API24设备显示了更详细的日志:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

我尝试了API21仿真器,API24硬件设备和API 28仿真器。只有API28仿真器不会产生该错误。

我用Google搜索,搜索,还向android issue tracker报告,我找不到任何解决方案,而android小组说这是预期的行为。所以我不知道该怎么办。我应该忽略错误消息吗?有人有这个问题吗?

build.gradle:

package com.example.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

MainActivity.java:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

activity_main.xml:

/usr/bin/curl -f --insecure -u admin:password -X GET -H 'Content-Type:application/json' http://artent-01.mydomain:8081/artifactory/api/system/ping

5 个答案:

答案 0 :(得分:0)

使用与最低sdk版本不兼容的类时,会发生这种情况。编译代码是因为它将代码留给您进行部署。尝试使用更高的最低sdk版本进行验证。

答案 1 :(得分:0)

我有支持库28.0.0,没有AndroidX。我没有更改API,只是重构了源代码。此异常发生在API 27仿真器上。应用程序启动,显示并在第二次崩溃后崩溃。我认为这是MultiDex或Firebase例外。有时,甚至调试也无法正常工作。

就我而言,我有一个愚蠢的错误。我调用了一个方法:

private fun showSlideShow() {
    StartActivity
    activity?.finish()
}

我想显示一个名为“ StartActivity”的活动,但忘了调用它的方法。

答案 2 :(得分:0)

好吧,似乎Google对修复它没有兴趣;我已经决定(暂时)强制使用支持库27。至少它可以修复少数支持lib 28崩溃的设备上的崩溃。

我正在使用的修复程序是将以下内容添加到build.gradle中,但是请注意,这是针对android的修复程序;仅适用于com.android.support库的用户。

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

答案 3 :(得分:0)

如果您将public class MainActivity extends AppCompatActivity中的“活动”替换为AppCompatActivity,则该警告将消失,因为该冲突与Android X中的AppCompat有关。

但是,如果您需要保持较旧设备的向后兼容性,则不是最佳解决方案。否则,您可以忽略此警告,直到出现任何修复程序为止。

答案 4 :(得分:0)

遇到类似问题,并且在尝试运行任何其他应用程序时也遇到相同的错误。使缓存无效或将“启动活动”设置为无效对我不起作用。但是在新的模拟器中运行应用程序是可行的。