Didn't find class on path DexPathList

2019-02-20 10:50发布

问题:

I was attempting to update my project to targetSdk 23, but I decided I wasn't up for it given all the deprecations. I didn't want to go through it so I reverted to an older version on mercurial, and now all I get is this error and I can't get the damn app to run again. What could possibly be going wrong?

12-21 02:36:00.545      437-437/com.elgami.customizer E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.elgami.customizer, PID: 437
    java.lang.RuntimeException: Unable to instantiate application com.elgami.application.GlobalApplication: java.lang.ClassNotFoundException: Didn't find class "com.elgami.application.GlobalApplication" on path: DexPathList[[zip file "/data/app/com.elgami.customizer-1/base.apk"],nativeLibraryDirectories=[/data/app/com.elgami.customizer-1/lib/arm, /vendor/lib, /system/lib]]
            at android.app.LoadedApk.makeApplication(LoadedApk.java:578)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4680)
            at android.app.ActivityThread.-wrap1(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.elgami.application.GlobalApplication" on path: DexPathList[[zip file "/data/app/com.elgami.customizer-1/base.apk"],nativeLibraryDirectories=[/data/app/com.elgami.customizer-1/lib/arm, /vendor/lib, /system/lib]]
            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:981)
            at android.app.LoadedApk.makeApplication(LoadedApk.java:573)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4680)
            at android.app.ActivityThread.-wrap1(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.elgami.customizer-1/base.apk
            at dalvik.system.DexFile.openDexFileNative(Native Method)
            at dalvik.system.DexFile.openDexFile(DexFile.java:295)
            at dalvik.system.DexFile.<init>(DexFile.java:80)
            at dalvik.system.DexFile.<init>(DexFile.java:59)
            at dalvik.system.DexPathList.loadDexFile(DexPathList.java:279)
            at dalvik.system.DexPathList.makePathElements(DexPathList.java:248)
            at dalvik.system.DexPathList.<init>(DexPathList.java:120)
            at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)
            at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:65)
            at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:58)
            at android.app.LoadedApk.getClassLoader(LoadedApk.java:376)
            at android.app.LoadedApk.makeApplication(LoadedApk.java:568)
            ... 9 more
    Suppressed: java.lang.ClassNotFoundException: com.elgami.application.GlobalApplication
            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)
            ... 12 more
     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

My build file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'Google Inc.:Google APIs:21'
    buildToolsVersion '21.1.2'

    defaultConfig {
        applicationId "com.elgami.customizer"
        minSdkVersion 14
        targetSdkVersion 21
    }

    buildTypes {
        release {
            minifyEnabled false
            //runProguard false
            //proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

repositories {
    mavenCentral()
    maven { url "https://jitpack.io" }
}

dependencies {
    compile 'com.ogaclejapan.smarttablayout:library:1.5.0@aar'
    compile 'com.github.antonyt:InfiniteViewPager:v1.0.0'
    compile 'com.android.support:appcompat-v7:22.2.0'
    // recyclerview
    compile 'com.android.support:recyclerview-v7:23.1.1'
    // google analytics
    compile 'com.google.android.gms:play-services-analytics:8.3.0'
    // pager sliding strip
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    // http library (for using beanstream REST)
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
    // amaazon S3 uploads
    compile 'com.amazonaws:aws-android-sdk-s3:2.1.+'
    // paypal purchasing
    compile files('libs/PayPalAndroidSDK-2.7.1.jar')
    // Module dependency on ParseLoginUI library sources
    compile project(':ParseLoginUI')
    // Parse libs
    compile files('libs/ParseCrashReporting-1.9.2.jar')
    compile files('libs/Parse-1.9.1.jar')
    compile files('libs/ParseFacebookUtilsV4-1.9.1.jar')
    // android support v4
    compile files('libs/android-support-v4.jar')
    // facebook SDK
    compile 'com.facebook.android:facebook-android-sdk:4.1.0'
    //butterknife
    compile 'com.jakewharton:butterknife:6.1.0'
    // Subsampling-scale-image-view (for templating)
    //compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.1.4'
    compile files('libs/AppRater.jar')
}

回答1:

Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multidex configuration.

  1. Change your Gradle build configuration to enable multidex
  2. Modify your manifest to reference the MultiDexApplication class

Modify your app Gradle build file configuration to include the support library and enable multidex output .

    android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 21
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

For more details you can visit

DexIndexOverflowException Only When Running Tests