未知错误:在路径:DexPathList上找不到类

时间:2019-07-24 19:49:57

标签: java android

我的应用程序最近崩溃了,无论我做了什么更改都无法正常工作。之前它工作得很好,但是在重构某些变量/类时我一定犯了一个错误。从LOGCAT返回的错误提到了我的项目中从未使用或实现的类NotifyStart,因此我不知道它来自何处。我将下面的LOGCAT返回的错误包括在内。

我曾尝试清理和重建该项目并禁用其即时运行功能,但到目前为止,没有任何效果。该应用程序将无法启动,并且在Home活动有机会弹出之前崩溃。


2019-07-24 20:38:57.065 27709-27709/com.example.camerakitqr E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.camerakitqr, PID: 27709
    java.lang.RuntimeException: Unable to instantiate application com.example.camerakitqr.NotifiyStart: java.lang.ClassNotFoundException: Didn't find class "com.example.camerakitqr.NotifiyStart" on path: DexPathList[[zip file "/data/app/com.example.camerakitqr-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.camerakitqr-1/lib/arm64, /system/lib64, /vendor/lib64, /system/vendor/lib64]]
        at android.app.LoadedApk.makeApplication(LoadedApk.java:807)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5477)
        at android.app.ActivityThread.-wrap2(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1595)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:203)
        at android.app.ActivityThread.main(ActivityThread.java:6251)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.camerakitqr.NotifiyStart" on path: DexPathList[[zip file "/data/app/com.example.camerakitqr-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.camerakitqr-1/lib/arm64, /system/lib64, /vendor/lib64, /system/vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.Instrumentation.newApplication(Instrumentation.java:992)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:801)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5477) 
        at android.app.ActivityThread.-wrap2(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1595) 
        at android.os.Handler.dispatchMessage(Handler.java:110) 
        at android.os.Looper.loop(Looper.java:203) 
        at android.app.ActivityThread.main(ActivityThread.java:6251) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
 

1 个答案:

答案 0 :(得分:1)

您必须为拥有超过64K方法的应用启用multidex

修改build.gradle:

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0"

         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 22

             // Enabling multidex support.
             multiDexEnabled true
         }
}

dependencies {
    implementation 'com.android.support:multidex:1.0.3'
}

如果您正在运行单元测试,则将其包含在Application类中:

public class YouApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

}

或者只是让您的应用程序类扩展MultiDexApplication

public class Application extends MultiDexApplication {

}

注意: Android 5.0(API级别21)及更高版本使用了本机支持多义化的ART。因此,如果您的minSdkVersion为21或更高,则不需要multidex支持库。