无法实例化应用程序 原因:java.lang.ClassNotFoundException:在路径上找不到 class:DexPathList

Unable to instantiate application Caused by: java.lang.ClassNotFoundException: Didn't find class on path: DexPathList

今天我遇到了一个奇怪的问题,我的应用程序突然停止在我的 USB 插入设备上运行。但是,它可以 运行 在其他真实设备和模拟器设备上正常运行。

屏幕上的错误对话框与往常一样:不幸的是 "your app name" 已停止。

为了获取错误消息,我 运行 我的应用程序处于调试模式并看到:

FATAL EXCEPTION: main
              Process: com.yourapp.packagename, PID: 20036
              java.lang.RuntimeException: Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.IllegalStateException: java.lang.ClassNotFoundException: android.support.multidex.MultiDexApplication
                  at android.app.LoadedApk.makeApplication(LoadedApk.java:676)
                  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6294)
                  at android.app.ActivityThread.access00(ActivityThread.java:222)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1861)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:158)
                  at android.app.ActivityThread.main(ActivityThread.java:7229)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
               Caused by: java.lang.IllegalStateException: java.lang.ClassNotFoundException: android.support.multidex.MultiDexApplication
                  at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:220)
                  at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239)
                  at android.app.Application.attach(Application.java:211)
                  at android.app.Instrumentation.newApplication(Instrumentation.java:1020)
                  at android.app.Instrumentation.newApplication(Instrumentation.java:1004)
                  at android.app.LoadedApk.makeApplication(LoadedApk.java:666)
                  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6294) 
                  at android.app.ActivityThread.access00(ActivityThread.java:222) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1861) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:158) 
                  at android.app.ActivityThread.main(ActivityThread.java:7229) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
               Caused by: java.lang.ClassNotFoundException: android.support.multidex.MultiDexApplication
                  at java.lang.Class.classForName(Native Method)
                  at java.lang.Class.forName(Class.java:324)
                  at java.lang.Class.forName(Class.java:285)
                  at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:209)
                  at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239) 
                  at android.app.Application.attach(Application.java:211) 
                  at android.app.Instrumentation.newApplication(Instrumentation.java:1020) 
                  at android.app.Instrumentation.newApplication(Instrumentation.java:1004) 
                  at android.app.LoadedApk.makeApplication(LoadedApk.java:666) 
                  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6294) 
                  at android.app.ActivityThread.access00(ActivityThread.java:222) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1861) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:158) 
                  at android.app.ActivityThread.main(ActivityThread.java:7229) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
               Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/com.yourapp.packagename-1/base.apk"],nativeLibraryDirectories=[/data/app/com.yourapp.packagename-1/lib/arm64, /vendor/lib64, /system/lib64]]
                  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                  at java.lang.Class.classForName(Native Method) 
                  at java.lang.Class.forName(Class.java:324) 
                  at java.lang.Class.forName(Class.java:285) 
                  at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:209) 
                  at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:239) 
                  at android.app.Application.attach(Application.java:211) 
                  at android.app.Instrumentation.newApplication(Instrumentation.java:1020) 
                  at android.app.Instrumentation.newApplication(Instrumentation.java:1004) 
                  at android.app.LoadedApk.makeApplication(LoadedApk.java:666) 
                  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6294) 
                  at android.app.ActivityThread.access00(ActivityThread.java:222) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1861) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:158) 
                  at android.app.ActivityThread.main(ActivityThread.java:7229) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                Suppressed: java.lang.ClassNotFoundException: android.support.multidex.MultiDexApplication
                  at java.lang.Class.classForName(Native Method)
                  at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
                  at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                        ... 19 more
               Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

清除和重建不起作用。 卸载并重新安装应用程序不起作用。 重新启动 Android Studio 仍然无法正常工作。

在与这个错误斗争了一个小时后,我通过禁用 Instant 运行 修复了这个问题,我的应用程序 运行 又恢复正常了。