Irving Crespo
Irving Crespo

Reputation: 11

Didn't find class XXXX on path: DexPathList only in API 22 or lollipop

I've had a problem for a few days. When I run my project in a device running Android lollipop, throws this error, but in android 6 or higher, this doesn't happen.

FATAL EXCEPTION: main Process: com.example.dell.sportspicken, PID: 26780 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.dell.sportspicken/com.example.dell.sportspicken.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.dell.sportspicken.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.dell.sportspicken-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.dell.sportspicken-2/lib/arm, /vendor/lib, /system/lib, /flex/resource/apks/system_apks/libs]] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2605) at android.app.ActivityThread.access$800(ActivityThread.java:178) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:204) at android.app.ActivityThread.main(ActivityThread.java:5643) 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:960) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.dell.sportspicken.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.dell.sportspicken-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.dell.sportspicken-2/lib/arm, /vendor/lib, /system/lib, /flex/resource/apks/system_apks/libs]] 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:1071) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2605)  at android.app.ActivityThread.access$800(ActivityThread.java:178)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)  at android.os.Handler.dispatchMessage(Handler.java:111)  at android.os.Looper.loop(Looper.java:204)  at android.app.ActivityThread.main(ActivityThread.java:5643)  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:960)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)  Suppressed: java.lang.ClassNotFoundException: com.example.dell.sportspicken.MainActivity 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

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
    applicationId "com.example.dell.sportspicken"
    minSdkVersion 21
    targetSdkVersion 25
    versionCode 1
    multiDexEnabled true
    versionName "1.0"

   testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary = true
    ndk {
        //abiFilter "armeabi-v7a"
    }
}
packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'

    exclude 'META-INF/ASL2.0'
    exclude "builddef.lst"
    exclude "isoparser-default.properties"
    exclude "version.txt"

}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
dexOptions {
    incremental true
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}
}

repositories {
    jcenter()
    mavenCentral()
    maven { url "https://dl.bintray.com/hani-momanii/maven" }
    maven { url 'https://maven.google.com' }
    maven { url "https://dl.bintray.com/drummer-aidan/maven" }
    maven { url "https://jitpack.io" }
    maven { url  "https://dl.bintray.com/qiscustech/maven" }
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':ffmpeg4android_lib')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
{
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude group: 'com.google.android.gms', module: 'play-services-base'
    exclude group: 'com.google.android.gms', module: 'play-services-maps'
})
compile('io.socket:engine.io-client:1.0.0') {
// excluding org.json which is provided by Android
    exclude group: 'org.json', module: 'json'
}
//compile 'com.github.hani-momanii:SuperNova-Emoji:1.1'
compile 'com.android.support:multidex:1.0.1'
// core and commons
compile 'com.google.android.gms:play-services-gcm:10.2.1'
compile project(path: ':ffmpeg4android_lib')
compile 'com.github.halilozercan:BetterVideoPlayer:1.1.0'
compile 'io.socket:socket.io-client:0.6.3'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.google.android.gms:play-services-base:11.0.4'
compile 'com.google.android.gms:play-services-location:11.0.4'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services-gcm:11.0.4'
compile 'com.github.danylovolokh:hashtag-helper:1.1.0'
compile 'com.scalified:fab:1.1.3'
compile 'com.github.clans:fab:1.6.4'
compile 'com.hendraanggrian:socialview-core:0.16.3'
compile 'com.hendraanggrian:socialview-commons:0.16.3'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:cardview-v7:25.2.0'
compile 'com.github.whalemare:sheetmenu:1.3.3'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
compile 'com.github.zomato:androidphotofilters:1.0.1'
compile 'com.google.android.gms:play-services-places:11.0.4'
compile 'hanks.xyz:smallbang-library:0.1.2'
compile 'org.ocpsoft.prettytime:prettytime:4.0.1.Final'
compile 'net.ypresto.androidtranscoder:android-transcoder:0.2.0'
compile 'com.github.danylovolokh:video-player-manager:0.2.0'
compile 'com.google.android.gms:play-services-auth:11.0.4'
compile 'com.android.support:support-v4:25.+'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.code.gson:gson:2.4'
compile 'com.tuyenmonkey:mkloader:1.3.0'
compile 'de.codecrafters.tableview:tableview:2.6.0'
compile 'com.github.aakira:expandable-layout:1.6.0@aar'
compile 'com.cleveroad:adaptivetablelayout:1.0.1'
compile 'com.github.nkzawa:socket.io-client:0.3.0'
compile 'com.github.mukeshsolanki:photofilter:1.0.2'
compile 'jp.wasabeef:blurry:2.0.2'
compile 'com.github.chathuralakmal:AndroidImagePopup:1.0.9'
compile 'com.yovenny.VideoCompress:videocompress:1.0.0'
compile 'com.facebook.fresco:fresco:1.4.0'
compile 'com.iceteck.silicompressorr:silicompressor:2.0'
compile 'com.nex3z:notification-badge:0.2.0'
compile 'com.steelkiwi:badge-holder-view:1.1.0'
compile 'me.relex:photodraweeview:1.1.3'
compile 'com.github.danylovolokh:list-visibility-utils:0.2.0'
compile 'com.yqritc:android-scalablevideoview:1.0.4'
compile 'hani.momanii.supernova_emoji_library:supernova-emoji-library:0.0.2'
compile 'com.google.android.gms:play-services-plus:11.0.4'
compile 'com.github.andyxialm:ColorDialog:1.0.0'
compile 'id.zelory:compressor:2.1.0'
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.+'
compile 'com.afollestad:material-camera:0.4.4'
compile 'org.apache.commons:commons-lang3:3.0'
compile 'io.viper:io.viper:8'
compile 'org.json:json:20151123'
compile 'com.chauthai.overscroll:overscroll-bouncy:0.1.1'
compile 'com.googlecode.ez-vcard:ez-vcard:0.10.3'
//File picker
compile 'com.qiscus.utils:jupuk:1.0.1'
//glide

//compile group: 'com.github.bumptech.glide', name: 'glide', version: '3.8.0'

//Image loader
compile 'com.qiscus.nirmana:nirmana:1.0.0'
//contador
compile 'com.github.iwgang:countdownview:2.1.6'
// animators
compile 'jp.wasabeef:recyclerview-animators:2.2.7'
testCompile 'junit:junit:4.12'
}

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    def requested = details.requested
    if (requested.group == 'com.android.support') {
        if (!requested.name.startsWith("multidex")) {
            details.useVersion '25.3.0'
        }
    }
}
}

Upvotes: 1

Views: 802

Answers (1)

AndrWeisR
AndrWeisR

Reputation: 1226

See this Android developer article for a description of the problem and a solution:

When building each DEX file for a multidex app, the build tools perform complex decision-making to determine which classes are needed in the primary DEX file so that your app can start successfully. If any class that's required during startup is not provided in the primary DEX file, then your app crashes with the error java.lang.NoClassDefFoundError.

This shouldn't happen for code that's accessed directly from your app code because the build tools recognize those code paths, but it can happen when the code paths are less visible such as when a library you use has complex dependencies. For example, if the code uses introspection or invocation of Java methods from native code, then those classes might not be recognized as required in the primary DEX file.

So if you receive java.lang.NoClassDefFoundError, then you must manually specify these additional classes as required in the primary DEX file by declaring them with the multiDexKeepFile or the multiDexKeepProguard property in your build type. If a class is matched in either the multiDexKeepFile or the multiDexKeepProguard file, then that class is added to the primary DEX file.

Upvotes: 0

Related Questions