拒绝在以前失败的类java.lang.class上重新初始化<;android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>;supportLib=28

拒绝在以前失败的类java.lang.class上重新初始化<;android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>;supportLib=28,android,Android,这种奇怪的logcat消息始于我切换到supportLibrary 28时,而不是27.1.1时。我尝试了一个空的默认项目,结果完全一样 这个问题很容易重复 使用空活动创建新项目,并在除API28 emulator之外的emulator上运行。它将在我的API21模拟器上显示该错误: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhand

这种奇怪的logcat消息始于我切换到supportLibrary 28时,而不是27.1.1时。我尝试了一个空的默认项目,结果完全一样

这个问题很容易重复

使用空活动创建新项目,并在除API28 emulator之外的emulator上运行。它将在我的API21模拟器上显示该错误:

Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
MainActivity.java:

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);
    }
}
activity_main.xml:

<?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>


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

好吧,因为谷歌似乎对修复它不感兴趣;我决定(现在)强制使用支持库27;至少它修复了少数支持lib 28 crash on的设备上的崩溃

我正在使用的修复程序是在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 "27.+"
            }
        }
    }
}

如果将AppCompatActivity替换为
公共类MainActivity扩展AppCompatActivity
中的Activity,则警告将消失,因为冲突与Android X中的AppCompat相关


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

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

它真的会导致任何问题吗?这是一个信息级日志。你可能应该自己在问题追踪器上报告。不,没有。应用程序按预期运行。是的,我报告了。它是信息级别,但会产生异常。我应该忽略它吗?有结果吗?我有同样的issue@RevanthKrishnaKumarV. 很抱歉,但是没有。而且,AndroidXI上也发生了同样的问题,但发现它确实会导致应用程序崩溃,但仅在某些设备上。就我而言,崩溃发生在NVidea平板电脑上。大多数设备都能工作,但也有少数设备会崩溃,到目前为止还没有找到解决方案。感谢您的回答,但这不是一个针对较低API设备的解决方案。我在问题中提到了这一点。上述人员究竟在做什么?为什么我要添加它,而不是将依赖项保留在27.x.x级别?如果您的项目使用其他第三方库,这些库可能会导入较新的支持库(以及最新的wins)。上面的代码搜索所有库中的所有依赖项,并用所需的特定版本替换这些依赖项。如果只更改依赖项,那么最终可能会通过其他依赖项得到更新的版本。
<?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>
configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == "com.android.support") {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion "27.+"
            }
        }
    }
}