4

I've read a few answers on this site with the same or similar error messages, and I've tried all the solutions already. Sadly, none of them have worked so far.

My gradle files all look like they're properly set up for Multidex, the Application class extends MultiDexApplication and is referenced correctly in the manifest, I've cleaned all caches and restarted the IDE, deleting builds from the project and the device and re-building/re-installing, etc. etc.

Inspecting the APK, I found the Application in classes2.dex, correctly referencing .super Landroidx/multidex/MultiDexApplication;

The stack I'm getting is like this:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.<REDACTED>, PID: 25475
    java.lang.RuntimeException: Unable to instantiate application com.<REDACTED>.Application: java.lang.ClassNotFoundException: Didn't find class "com.<REDACTED>.Application" on path: DexPathList[[zip file "/data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/base.apk"],nativeLibraryDirectories=[/data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/lib/arm64, /system/lib64, /system/system_ext/lib64]]
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1306)
        at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7401)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7374)
        at android.app.ActivityThread.access$1500(ActivityThread.java:301)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2118)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:246)
        at android.app.ActivityThread.main(ActivityThread.java:8425)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.<REDACTED>.Application" on path: DexPathList[[zip file "/data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/base.apk"],nativeLibraryDirectories=[/data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/lib/arm64, /system/lib64, /system/system_ext/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
        at android.app.Instrumentation.newApplication(Instrumentation.java:1158)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1298)
        at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7401) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7374) 
        at android.app.ActivityThread.access$1500(ActivityThread.java:301) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2118) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:246) 
        at android.app.ActivityThread.main(ActivityThread.java:8425) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) 
        Suppressed: java.io.IOException: Failed to open dex files from /data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/base.apk because: Failure to verify dex file '/data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/base.apk': Bad index for method_handle_item method_idx: ffff >= de57
        at dalvik.system.DexFile.openDexFileNative(Native Method)
        at dalvik.system.DexFile.openDexFile(DexFile.java:367)
        at dalvik.system.DexFile.<init>(DexFile.java:109)
        at dalvik.system.DexFile.<init>(DexFile.java:82)
        at dalvik.system.DexPathList.loadDexFile(DexPathList.java:439)
        at dalvik.system.DexPathList.makeDexElements(DexPathList.java:398)
        at dalvik.system.DexPathList.<init>(DexPathList.java:166)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:129)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:104)
        at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:74)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:87)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:116)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:114)
        at android.app.ApplicationLoaders.getClassLoaderWithSharedLibraries(ApplicationLoaders.java:60)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:933)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:990)
        at android.app.LoadedApk.getResources(LoadedApk.java:1234)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2788)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2780)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7263)
                ... 8 more

Can anyone figure out what this is all about?

Ky -
  • 30,724
  • 51
  • 192
  • 308
  • Something seems to be messed up with the DEX file. If you do a full clean-and-rebuild of the project, does the problem persist? – CommonsWare Apr 07 '21 at 18:24
  • Yes. @CommonsWare. I'll add that to the question – Ky - Apr 07 '21 at 19:02
  • Do you have `buildToolsVersion` specified for this module in `build.gradle`? If so, is it up to date? Similarly, is your Android Gradle Plugin version up to date? It feels like the build tools are screwing up somehow, though I don't see this specific issue in the issue tracker. – CommonsWare Apr 07 '21 at 19:08
  • @CommonsWare yes, it's set to `29.0.3`, the same as the project-level Gradle file. I'm using Android Gradle `4.1.3` – Ky - Apr 07 '21 at 19:28
  • "it's set to 29.0.3, the same as the project-level Gradle file" -- that's a bit older. Have you tried using something newer? Or removing `buildToolsVersion` outright and letting the plugin decide the version to use? – CommonsWare Apr 07 '21 at 20:01
  • Thank you for helping me, @CommonsWare! These ideas were all very specific and good. Turns out it was something about Crashlytics, which my teammate discovered. I've added that as an answer – Ky - Apr 07 '21 at 22:48

1 Answers1

1

In the module level build.gradle, we added these lines:

// Near the top
apply plugin: 'com.google.firebase.crashlytics'

// ... 

android {

    // ...

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
    
    // ...
}

// ...

I have no idea how this fixed this crash, but I suppose that's what I get for using "It just works" libraries.

Ky -
  • 30,724
  • 51
  • 192
  • 308