RuntimeException:无法实例化应用程序 com.company.app.Application:ClassNotFoundException

RuntimeException: Unable to instantiate application com.company.app.Application: ClassNotFoundException

我已经在该站点上阅读了一些具有相同或相似错误消息的答案,并且我已经尝试了所有解决方案。可悲的是,到目前为止,none 已经奏效了。

我的 gradle 文件看起来都已针对 Multidex 正确设置,Application class extends MultiDexApplication 并且在清单中被正确引用,我'已清除所有缓存并重新启动 IDE,从项目和设备中删除构建和 re-building/re-installing,等等

检查 APK,我在 classes2.dex 中找到了 Application,正确引用了 .super Landroidx/multidex/MultiDexApplication;

我得到的堆栈是这样的:

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.access00(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.access00(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

谁能知道这是怎么回事?

模块级别 build.gradle,我们添加了这些行:

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

// ... 

android {

    // ...

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

// ...

我不知道这是如何解决这次崩溃的,但我想这就是我使用“It just works”库得到的结果。