未在路径上找到 class:Android 库上的 DexPathList

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

我正在开发一个 Android 库来对我的应用程序中的一些工作进行模块化,我使用改造来使用一些 Web API。

当我在同一个 Android Studio 项目中的示例应用程序(编译库模块)中编译和使用它时,一切正常,但是当我使用工件中的库时,出现错误 Didn't find class on Path....

我的 gradle.build 文件包含这个

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'
}

我已经尝试过 retrofit 和 retrofit2,但我在实现该库的应用程序中仍然遇到同样的崩溃问题

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 Android运行时:在 dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.j

我认为这是一个简单的 android 工作室问题,以正确的顺序重新排列导入以防万一,然后清理并构建您的项目。

这解决了我的问题

这就是我解决问题的方法!

我的问题不在应用程序中,而是在我的库中,我在 gradle 文件中设置了错误的发布任务。这就是你应该为 Bintray 做的。

task generateSourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier 'sources'
}

artifacts {
    archives generateSourcesJar
}

bintray {
    ...
    configurations = ['archives']
}

检查您的人工框架,您应该如何将依赖项添加到您的库。

今天我也遇到了同样的问题。当我浏览 Github 提供的文档时,由于一些更改,我发现您将面临此错误。如果您使用的是改造版本 2.7.0,则很可能会遇到此错误(就我而言,我也使用的是改造版本。因此,为了解决该问题,我执行了以下步骤:

  1. 我在我的 android 项目中添加了 Java 版本 8 支持启用 添加 Java 版本 8 支持。打开 Gradle 项目级别的文件并在内部 android 括号添加下面的代码。

    android {
    
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    }
    
  2. 并在同一个 gradle 文件中添加下面提到的依赖项

    implementation "com.squareup.okhttp3:okhttp:3.13.1"
    

下面简要提到了为什么要进行上述更改 link

Clik to find more details of additional informatio

希望这会有所帮助并节省一些时间。

试试这个,

compileOptions{
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    
    }