新建一個安卓項目, compileSdkVersion 29,然後啟動MainActivity就看到 Logcat中有警告信息:
1Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener;
雖然不會拋出錯誤或異常,但是看到也很噁心。
解決方法,在 build.gradle
文件中添加以下配置
1configurations.all {
2 resolutionStrategy.eachDependency { DependencyResolveDetails details ->
3 def requested = details.requested
4 if (requested.group == "androidx.appcompat") {
5 if (!requested.name.startsWith("multidex")) {
6 details.useVersion "1.+"
7 }
8 }
9 }
10}
Reference
- 迁移AndroidX 终端机型SDK版本低于android-28遇到的报错信息
- How to resolve NoClassDefFoundError: Failed resolution of: Landroid/view/View$OnUnhandledKeyEventListener
- [AndroidX:Appcompat I:art error android.view.View$OnUnhandledKeyEventListener](https://stackoverflow.com/questions/51782548/androidxappcompat-iart-error-android-view-viewonunhandledkeyeventlistener]
- NoClassDefFoundErrorの解決方法:Landroid / view / View $OnUnhandledKeyEventListenerの解決に失敗しました。