ClassNotFoundException:config_inputEventCompatProcessorOverrideClassName android,运行 在 androidx 上崩溃

ClassNotFoundException: config_inputEventCompatProcessorOverrideClassName androidx, running on andoridx crashes

迁移到 AndroidX(29) 后 运行 在 AndroidX 设备上崩溃显示

ClassNotFoundException: config_inputEventCompatProcessorOverrideClassName

项目编译运行在andorid10.0启动时崩溃 单击 editText 时出现此错误,请在此处输入代码

NullPointerException: Attempt to invoke virtual method 'java.util.List android.view.InputEventCompatProcessor.processInputEventForCompatibility(android.view.InputEvent)' on a null object reference

project/build.gradle

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
        maven { url 'https://jitpack.io' }
        google()
    }
    dependencies {
//        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath 'com.google.gms:google-services:3.0.0'
//        classpath 'io.fabric.tools:gradle:1.+'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url 'https://maven.google.com' }
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
ext {
    // Sdk and tools
    minSdkVersion = 16
    targetSdkVersion = 26
    compileSdkVersion = 26
    buildToolsVersion = '26.0.0'

    // App dependencies
    supportLibraryVersion = '25.4.0'
    gsonVersion = '2.8.0'
    calligraphyVersion = '2.2.0'
    glideVersion = '3.7.0'
    roomDatabase = '1.0.0-alpha3'
    rx2FastAndroidNetworking = '1.0.0'

    dagger2Version = '2.16'
    rxjava2Version = '2.0.6'
    rxandroidVersion = '2.0.1'
    placeholderviewVersion = '0.6.1'
    debugDBVersion = '1.0.0'
    timberVersion = '4.5.1'
    lifecycle = '1.0.0-alpha3'

    retrofitVersion='2.3.0'
    GsonVersion='2.7'
    okhttpVersion= '3.8.0'
    googleplus= '11.0.0'//'10.2.0'//'11.0.4'
    glideversion= '4.1.1'

    //Test dependencies
    junitVersion = '4.12'
    espressoVersion = '2.2.2'
    mockitoVersion = '2.7.1'
}

app/build.gradle

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}
buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.27.1'
    }
}
android {
    compileSdkVersion 28
    signingConfigs {
        ReleaseConfig {
            keyAlias 'xxxxx'
            keyPassword 'xxxxx'
            storeFile file('../KeyStore/xxxxx.jks')
            storePassword 'xxxxx'
        }
    }
    defaultConfig {
        applicationId "bz.pei.driver"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        signingConfig signingConfigs.ReleaseConfig
        setProperty("archivesBaseName", "PEI Taxi_Driver_v$versionName")

    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    List<String> dirs = [
            'main',     // main sample code; look here for the interesting stuff.
            'common',   // components that are reused by multiple samples
            'template'] // boilerplate code that is generated by the sample template process
    sourceSets {
        main {
            dirs.each { dir ->
                java.srcDirs "src/${dir}/java"
                res.srcDirs "src/${dir}/res"
            }
        }
        androidTest.setRoot('tests')
        androidTest.java.srcDirs = ['tests/src']

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
    dataBinding.enabled = true
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //Crashlytics
    implementation('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
        transitive = true;
    }
    // dependency injection
    implementation "com.google.dagger:dagger:$rootProject.dagger2Version"
    annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.dagger2Version"
    annotationProcessor "com.google.dagger:dagger-android-processor:$rootProject.dagger2Version"
    implementation "com.google.dagger:dagger-android-support:$rootProject.dagger2Version"
    //Viewmodel
    implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
    implementation "com.squareup.retrofit2:converter-gson:$rootProject.retrofitVersion"
    implementation "com.squareup.okhttp3:logging-interceptor:$rootProject.okhttpVersion"
    implementation "com.google.android.gms:play-services-auth:$rootProject.googleplus"
    implementation "com.google.android.gms:play-services-maps:$rootProject.googleplus"
    implementation "com.google.android.gms:play-services-location:11.0.0"
    implementation 'com.google.maps.android:android-maps-utils:0.5+'
    implementation 'com.github.javiersantos:AppUpdater:2.7'
    implementation 'com.google.firebase:firebase-core:11.0.0'
    implementation 'com.google.firebase:firebase-messaging:11.0.0'
    implementation "com.github.bumptech.glide:glide:$rootProject.glideversion"
    implementation('io.socket:socket.io-client:1.0.0') {//0.8.3') {
        exclude group: 'org.json', module: 'json'
    }
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.intuit.sdp:sdp-android:1.0.4'
    implementation "com.google.android.gms:play-services-maps:$rootProject.googleplus"
    implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
    testImplementation 'junit:junit:4.12'

}
apply plugin: 'com.google.gms.google-services'
configurations.all {
    resolutionStrategy.force "com.android.support:support-annotations:$supportLibraryVersion"
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}

gradle-wrapper.properties

#Wed Nov 20 00:37:33 IST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

java.lang.ClassNotFoundException: config_inputEventCompatProcessorOverrideClassName
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:454)
    at java.lang.Class.forName(Class.java:379)
    at android.view.ViewRootImpl.<init>(ViewRootImpl.java:635)
    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:377)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:95)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4296)
    at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
 Caused by: java.lang.ClassNotFoundException: config_inputEventCompatProcessorOverrideClassName
    at java.lang.Class.classForName(Native Method)
    at java.lang.BootClassLoader.findClass(ClassLoader.java:1358)
    at java.lang.BootClassLoader.loadClass(ClassLoader.java:1418)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at java.lang.Class.classForName(Native Method) 
    at java.lang.Class.forName(Class.java:454) 
    at java.lang.Class.forName(Class.java:379) 
    at android.view.ViewRootImpl.<init>(ViewRootImpl.java:635) 
    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:377) 
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:95) 
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4296) 
    at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) 
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:214) 
    at android.app.ActivityThread.main(ActivityThread.java:7356) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
 Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List android.view.InputEventCompatProcessor.processInputEventForCompatibility(android.view.InputEvent)' on a null object reference
    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7614)
    at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:188)
    at android.os.MessageQueue.nativePollOnce(Native Method)
    at android.os.MessageQueue.next(MessageQueue.java:336)
    at android.os.Looper.loop(Looper.java:174)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

2019-11-21 06:41:59.007 27692-27692/bz.pei.driver E/AndroidRuntime:致命异常:main 进程:bz.pei.driver,PID:27692 java.lang.NullPointerException: 尝试在空对象引用上调用虚方法 'java.util.List android.view.InputEventCompatProcessor.processInputEventForCompatibility(android.view.InputEvent)' 在 android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7614) 在 android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:188) 在 android.os.MessageQueue.nativePollOnce(本机方法) 在 android.os.MessageQueue.next(MessageQueue.java:336) 在 android.os.Looper.loop(Looper.java:174) 在 android.app.ActivityThread.main(ActivityThread.java:7356) 在 java.lang.reflect.Method.invoke(本机方法) 在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

回答您的问题需要做一些说明

  1. 在您迁移到 androidx 之前应用程序是否运行良好?

  2. 该应用程序是否可以在其他设备上运行而不会崩溃但仅在 android 10.0 上崩溃?

  3. 你是否正确地重构了你的包名?如果您在清单或生成的代码中的文件名有一个以大写字母开头的包名称,'class not found exception' 可能会导致

您可以尝试将 Github link 粘贴(如果可能)到整个项目以进行正确调试。

但是,根据您粘贴的代码,您的项目 build.gradle ext 块中的 minsdkversion= 16 与您的应用程序 build.gradle 文件中的 minsdkversion= 15 不同。两个文件的 targetsdkversion 也不同

感谢所有支持我解决了问题,这是由于使用了已弃用的方法,这与迁移无关

@Override
public Resources getResources() {
    return new CustomResources(sharedPrefence, getAssets(), super.getResources().getDisplayMetrics(), super.getResources().getConfiguration());
}

自定义资源 class 无法在 androidX 中以这种方式使用,通过从 Baseactivity.java 中删除此方法解决了问题,感谢您的支持

我在 Android 10 上遇到了同样的问题。我使用了 Restring 库,它通过 attachBaseContext(newBase: Context) 注入了自定义 Resource 实现。这里的每个人都提到 Resource 的构造函数标记为已弃用,但它并没有真正导致问题。

我正在深入研究 Android 源代码,我发现了可以抛出 NPE 的真正原因。

来自 ViewRootImpl.java 的受影响行:

String processorOverrideName = context.getResources().getString(
                                    R.string.config_inputEventCompatProcessorOverrideClassName);
        if (processorOverrideName.isEmpty()) {
            // No compatibility processor override, using default.
            mInputCompatProcessor = new InputEventCompatProcessor(context);
        } else {
            InputEventCompatProcessor compatProcessor = null;
            try {
                final Class<? extends InputEventCompatProcessor> klass =
                        (Class<? extends InputEventCompatProcessor>) Class.forName(
                                processorOverrideName);
                compatProcessor = klass.getConstructor(Context.class).newInstance(context);
            } catch (Exception e) {
                Log.e(TAG, "Unable to create the InputEventCompatProcessor. ", e);
            } finally {
                mInputCompatProcessor = compatProcessor;
            }
        }

就我而言,使用 Restring 库,我定义了一种解析字符串键和 return 文本的新方法。如果密钥在我的字符串存储库(简单的 HashMap)中不可用或作为字符串资源不可用,它 return 将使用密钥本身。所以永远不会是空的,但根据代码,它将尝试加载为自定义 InputEventCompatProcessor,这将失败并且 mInputCompatProcessor 将是 null.

确保您的自定义 ResourcegetText() 的所有版本都尊重原始行为,并且不会导致 NPE 崩溃。例如,确保 R.string.config_inputEventCompatProcessorOverrideClassName 资源在不可用时将被解析为空字符串。

这将解决真正的问题,您仍然可以使用已弃用的 Resource 构造函数。