1

After Migrating to AndroidX(29) running on the AndroidX device Crashes showing

ClassNotFoundException: config_inputEventCompatProcessorOverrideClassName

the project compiles and runs it crashes when launched in andorid10.0 when clicked on the editText i get this error

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: FATAL EXCEPTION: main Process: bz.pei.driver, PID: 27692 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)

Mukesh
  • 63
  • 9

3 Answers3

5

I have faced with the same issue on Android 10. I used the Restring library which injects a custom Resource implementation through attachBaseContext(newBase: Context). Everyone here mentioned that constructor of Resource marked as deprecated, but it doesn't really cause a problem.

I was digging into the Android source code and I found the real reason that can throw NPE.

Affected lines from 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;
            }
        }

In my case, using Restring library, I defined a new way to resolve a string key and return text. If the key isn't available in my string repository (simple HashMap) or as a string resource, it returns with the key itself. So never will be empty, but according to the code it will try to load as custom InputEventCompatProcessor that will fail and mInputCompatProcessor will be null.

Make sure all verions of getText() in your custom Resource respect the original behavior and it won't cause NPE crash. For example make sure R.string.config_inputEventCompatProcessorOverrideClassName resource will be resolved as empty string when it's not available.

This will solve the real issue and you can still use the deprecated Resource constructor.

  • 1
    I wanna add some emphasis on the part about "Make sure all verions of getText() in your custom Resource respect the original behavior and it won't cause NPE crash." This is what was causing an issue for me. – Antoine Sep 25 '20 at 13:46
  • Unfortunately, this seems not works for me as well :( for getString, getText, getString, getText. is this right doing it with: `try { super.get*(...) } catch (NotFoundException) { "" }` – mochadwi Aug 10 '22 at 10:53
1

thanks for all the support i solved the issues, this was due to the usage of deprecated method, this was not related to migration

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

custom Resources class cannot be used in this way in androidX, by removing this method from Baseactivity.java solved the problem, thanks for all your suppor

Mukesh
  • 63
  • 9
0

There are a couple of clarifications needed to answer your question

  1. Was the app working fine before you migrated to androidx?

  2. Does the app work without crashing on other devices but crashes on just android 10.0?

  3. did you refactor your package names correctly? If your file names in the manifest or generated code have a package name starting with capital letters, 'class not found exception' could result

You can try pasting (if possible) the Github link to the whole project for proper debugging.

However, from the code you pasted, your minsdkversion= 16 in your project build.gradle ext block differs from the minsdkversion= 15 in your app build.gradle file. The targetsdkversion also differs in the two files

Oluwasegun Wahaab
  • 2,663
  • 3
  • 16
  • 19
  • thanks @Segun Wahaab, and 1- Yes app was working fine before migrating to AndroidX 2- Yes app works without crash in other devices and crashes in andoirdX 3- Yes i refracted the code and all the packages are in lowercase [source file for the project could you help](https://github.com/MukeshGreenDeveloper/PrUserNew) – Mukesh Nov 21 '19 at 14:49
  • I have just forked your repo and downloaded your code to android studio and about to start debugging. – Oluwasegun Wahaab Nov 21 '19 at 15:43
  • Meanwhile, I noticed you added the green checkbox to another answer in the previous question you asked here: https://stackoverflow.com/questions/58915112/debug-databindinggenbaseclassesdebug-databinding-activitysignupbinding-java-andr/58940668#58940668 . Adding the checkbox to an anwer which is not the direct answer to your issue could confuse future users – Oluwasegun Wahaab Nov 21 '19 at 15:50
  • There are quite a lot of errors in your project. some of these are related to calling new methods on older versions of android. You need to fix all these errors one after the other to prevent crashes at the user end. To see these errors, right-click the app directory, click 'analyze', then 'inspect code'. – Oluwasegun Wahaab Nov 21 '19 at 16:15
  • At least there are 9 errors related to calling new methods on older versions of android. You need to first check if the version of android is above or equal to the min supported version before you call these methods. Unless your code would crash on lower versions of android – Oluwasegun Wahaab Nov 21 '19 at 16:18
  • You could focus on fixing the android errors and ignore the warnings and typos for now – Oluwasegun Wahaab Nov 21 '19 at 16:28
  • thanks, could you point out one so that i could identify the rest error – Mukesh Nov 22 '19 at 07:23
  • To see these errors, right-click the app directory, click 'analyze', then 'inspect code' – Oluwasegun Wahaab Nov 22 '19 at 07:34
  • thanks **@Segun Wahaab**, i have fixed the error from analyze still shows the same error `java.lang.ClassNotFoundException: config_inputEventCompatProcessorOverrideClassName` – Mukesh Nov 27 '19 at 07:54
  • error when screen loaded `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)` – Mukesh Nov 27 '19 at 08:08
  • And error on click of editText of the loaded screen `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)` – Mukesh Nov 27 '19 at 08:08
  • post a link to your new error-free project on git hub – Oluwasegun Wahaab Nov 28 '19 at 05:35
  • updated code with removed old method errors [Source Code](https://github.com/MukeshGreenDeveloper/PrUserNew) – Mukesh Nov 28 '19 at 05:47
  • thanks for your support **@SegunWahaab** fixed the problem it was not related to migration Solutions https://stackoverflow.com/a/59129135/9191757 – Mukesh Dec 01 '19 at 19:28