Search code examples
androidretrofitretrofit2aar

Didn't find class on path: DexPathList on Android Library


I'm working on an Android Library to module some work on my app and I use retrofit to consume some web APIs.

When I compile and use it in my sample app (compiling the library module) in the same Android Studio project everything works fine, but when I use the library from the artifact I got the error Didn't find class on Path....

My gradle.build file contains this

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.squareup.retrofit2:converter-gson:2.0.2'
    compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'

    testCompile 'junit:junit:4.12'
    testCompile "org.mockito:mockito-core:1.+"
    testCompile "org.hamcrest:hamcrest-core:1.3"
    testCompile "org.hamcrest:hamcrest-library:1.3"
    testCompile 'org.robolectric:robolectric:3.0'
}

I've tried with retrofit and retrofit2 but I still got the same crash on my app implementing the library

Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.logging.HttpLoggingInterceptor" on path: DexPathList[[dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-support-annotations-23.3.0_471cb7629dd1bd2eaf19897f0bfa2e292d59a1a2-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-mx.segundamano.android-payments-library-0.1-SNAPSHOT_afd67b66a26310987e26f412f53082c415795025-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-internal_impl-23.3.0_ffb5ab0b136af54fef26d794f3208310ca6ef941-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-com.android.support-support-vector-drawable-23.3.0_2834a08897c09d9f4cf6a603048125bd86044324-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-com.android.support-support-v4-23.3.0_0fe06b17a4b2ae866e5066f3ea5bc8d596bd609e-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-com.android.support-multidex-1.0.1_9e5a739896463403b4d643ff254bf74dcc98371f-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-com.android.support-appcompat-v7-23.3.0_eba794855dfef17238864c6651afded84f82cf47-classes.dex", dex file "/data/data/mx.segundamano.paymentsdemo/files/instant-run/dex/slice-com.android.support-animated-vector-drawable-23.3.0_41e987bda5b0c3ecdbb65ba4dfa7c24496152077-classes.dex"],nativeLibraryDirectories=[/data/app/mx.segundamano.paymentsdemo-1/lib/arm64, /vendor/lib64, /system/lib64]]

05-11 11:40:03.737 4279 4279 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.j


Solution

  • This is how I solved my problem!

    My problem it wasn't in the app, it was in my library, I set wrong the publish task in my gradle file. This is how you should do it for Bintray.

    task generateSourcesJar(type: Jar) {
        from android.sourceSets.main.java.srcDirs
        classifier 'sources'
    }
    
    artifacts {
        archives generateSourcesJar
    }
    
    bintray {
        ...
        configurations = ['archives']
    }
    

    Check in your artifactory framework how you should add dependencies to your library.