错误日志:
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;
错误原因: 据百度搜索,导致这个问题的普遍原因Android API高版本与低版本的组件库不兼容导致
compileSdkVersion 28
defaultConfig {
...
targetSdkVersion 28
API 28 这个版本下就会出现这个问题 so我们将compileSdkVersion 和 targetSdkVersion 改成28以下
compileSdkVersion (28以下)
defaultConfig {
...
targetSdkVersion (28以下)
相关dependencies包也修改成相应的
dependencies {
implementation 'com.android.support:appcompat-v7:当前版本'
implementation 'com.android.support:design:当前版本'
implementation 'com.android.support:gridlayout-v7:当前版本'
}
如果以上操作你可以正常编译成功,那么恭喜你问题解决.BUT,BUT,BUT
当我们修改compileSdkVersion和targetSdkVersion 为低版本时,可能会出现编译错误
android studio 运行程序时 报错:finished with non-zero exit value 1
反正我当时内心是崩溃的,使用gradlew processDebugResources方法找到具体问题所在
No resource identifier found for attribute 'appComponentFactory' in package 'android'
我这个原因是第三方包 compile 'com.github.chrisbanes:PhotoView:+'使用的是最新版本2.3.0,该版本依赖androidx的相关包。而android support包与androidx不能同时存在,只能使用它们中的一种作为依赖,否则就会报上述的错误
解决方法:
1.在manifest的<application >加上
tools:replace="android:appComponentFactory"
android:appComponentFactory="任意字符"
2.在项目级别的build.gradle 的allprojects节点下面加上添加如下代码
configurations.all {
resolutionStrategy.eachDependency {
DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '26.1.0'
}
}
}
}
至此我的问题解决,欢迎大家沟通