在运行时获取ClassNotFoundException,无法在dexpathlist中找到活动

时间:2017-12-30 11:17:50

标签: android android-gradle android-multidex

这是我尝试过的一系列事项:

  1. 已禁用即时运行(之前已禁用,因为我无论如何也无法使用它)
  2. 清理并重建我的项目
  3. 项目的检查名称无处不在
  4. multiDexEnabled设置为true
  5. Followed all steps shown in this link
  6. 无效缓存&重新启动
  7. 创建了一个新项目并复制了以前项目中的代码
  8. 在Manifest中添加MultiDexApplication行之前,我得到了以下stacktrace:

    E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.prajjwal.myfreight_0, PID: 27367
                  java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.prajjwal.myfreight_0/com.prajjwal.myfreight_0.Splash}: java.lang.ClassNotFoundException: Didn't find class "com.prajjwal.myfreight_0.Splash" on path: DexPathList[[zip file "/data/app/com.prajjwal.myfreight_0-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2486)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2656)
                      at android.app.ActivityThread.access$800(ActivityThread.java:178)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1512)
                      at android.os.Handler.dispatchMessage(Handler.java:111)
                      at android.os.Looper.loop(Looper.java:194)
                      at android.app.ActivityThread.main(ActivityThread.java:5692)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at java.lang.reflect.Method.invoke(Method.java:372)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
                   Caused by: java.lang.ClassNotFoundException: Didn't find class "com.prajjwal.myfreight_0.Splash" on path: DexPathList[[zip file "/data/app/com.prajjwal.myfreight_0-1/base.apk"],nativeLibraryDirectories=[/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 android.app.Instrumentation.newActivity(Instrumentation.java:1074)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2463)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2656) 
                      at android.app.ActivityThread.access$800(ActivityThread.java:178) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1512) 
                      at android.os.Handler.dispatchMessage(Handler.java:111) 
                      at android.os.Looper.loop(Looper.java:194) 
                      at android.app.ActivityThread.main(ActivityThread.java:5692) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at java.lang.reflect.Method.invoke(Method.java:372) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754) 
                    Suppressed: java.lang.ClassNotFoundException: com.prajjwal.myfreight_0.Splash
                      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)
                            ... 13 more
                   Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
    

    添加该行之后,我得到了这个:

    12-30 16:44:12.980 5272-5272/prajjwal.com.myfreight E/AndroidRuntime: FATAL EXCEPTION: main
                                                                      Process: prajjwal.com.myfreight, PID: 5272
                                                                      java.lang.RuntimeException: Unable to instantiate application android.support.multidex.MultiDexApplication: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/prajjwal.com.myfreight-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
                                                                          at android.app.LoadedApk.makeApplication(LoadedApk.java:572)
                                                                          at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4883)
                                                                          at android.app.ActivityThread.access$1500(ActivityThread.java:178)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1573)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:111)
                                                                          at android.os.Looper.loop(Looper.java:194)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5692)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at java.lang.reflect.Method.invoke(Method.java:372)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
                                                                       Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/prajjwal.com.myfreight-1/base.apk"],nativeLibraryDirectories=[/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 android.app.Instrumentation.newApplication(Instrumentation.java:988)
                                                                          at android.app.LoadedApk.makeApplication(LoadedApk.java:567)
                                                                          at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4883) 
                                                                          at android.app.ActivityThread.access$1500(ActivityThread.java:178) 
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1573) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:111) 
                                                                          at android.os.Looper.loop(Looper.java:194) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5692) 
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754) 
                                                                        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)
                                                                                ... 13 more
                                                                       Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
    

    我在我的智慧结束时会感激任何帮助。

    编辑:第一个堆栈跟踪来自旧项目,第二个来自我创建的新项目

    的build.gradle:

    apply plugin: 'com.android.application'
    
    android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "prajjwal.com.myfreight"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    
    dexOptions {
    
        javaMaxHeapSize "5120"
    }
    
    afterEvaluate {
        tasks.matching {
            it.name.startsWith('dex')
        }.each { dx ->
            if (dx.additionalParameters == null) {
                dx.additionalParameters = ['--multi-dex']
            } else {
                dx.additionalParameters += '--multi-dex'
            }
        }
    }
    
    subprojects {
        project.plugins.whenPluginAdded { plugin ->
            if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
                project.android.dexOptions.preDexLibraries = false
            } else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
                project.android.dexOptions.preDexLibraries = false
            }
        }
    }
     }
    
     dependencies {
    
    /*implementation 'com.android.support:appcompat-v7:25.4.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'*/
    compile files('libs/jtds-1.2.8-a46da18a7c06f34fb19c38538665cbe1.jar')
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:support-v4:25.4.0'
    compile 'com.android.support:gridlayout-v7:25.4.0'
    compile 'com.android.support:appcompat-v7:25.4.0'
    compile 'com.android.support:design:25.4.0'
    compile 'com.rengwuxian.materialedittext:library:2.1.4'
    compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    /*testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'*/
    }
    

1 个答案:

答案 0 :(得分:0)

使用此

compileSdkVersion "26.0.0"
buildToolsVersion "26.0.0"

而不是

compileSdkVersion 25
buildToolsVersion "26.0.0"