问题描述
当我切换到supportLibrary 28时,开始出现这种奇怪的logcat消息,而在27.1.1上没有发生.我尝试了一个空的默认项目,结果完全一样.
This weird logcat messages started when I switched to supportLibrary 28, not happens on 27.1.1. I tried with an empty default project and the result exactly the same.
问题很容易重现,
创建一个活动为空的新项目,并在除API28仿真器之外的仿真器上运行.它将在我的API21模拟器上给出该错误:
Create a new project with an empty activity and run on an emulator except API28 emulator. It'll give that error on my API21 emulator:
Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
我的API24设备显示了更详细的日志:
My API24 device shows more detailed log:
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)
我尝试了API21仿真器,API24硬件设备和API 28仿真器.只有API28仿真器不会产生该错误.
I tried API21 emulator, API24 hardware device and API 28 emulator. Only API28 emulator didn't produce that error.
我用Google搜索,搜索,还向 android问题跟踪器报告,我找不到任何内容解决方案和android小组说这是预期的行为.所以我不知道该怎么办.我应该忽略错误消息吗?有人有这个问题吗?
I googled, searched SO and also reported to android issue tracker I can't find any solution and android team says that is an intended behavior. So I don't know what to do. Should I ignore an error message? Is there anybody have this issue?
build.gradle:
build.gradle:
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'
}
MainActivity.java:
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:
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>
推荐答案
好吧,因为Google似乎无意对其进行修复;我已经决定(暂时)强制使用支持库27.至少它可以修复少数支持lib 28崩溃的设备上的崩溃.
Well, as it appears that Google isn't interested in fixing it; I've decided to (for now) force using support library 27; at least it fixes the crashes on the few devices that support lib 28 crash on.
我正在使用的修复程序是将以下内容添加到build.gradle中,但是请注意,这是针对android的修复程序;仅适用于com.android.support库的用户.
The fix that I'm using is adding the following into build.gradle however note, this is for a fix for android; only works for users of com.android.support libraries.
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == "com.android.support") {
if (!requested.name.startsWith("multidex")) {
details.useVersion "27.+"
}
}
}
}
这篇关于拒绝对先前失败的类java.lang.Class< android.support.v4.view.ViewCompat $ OnUnhandledKeyEventListenerWrapper>进行重新初始化supportLib = 28的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!