原因: java.lang.NoClassDefFoundError: 使用引导类装入器找不到类;没有可用的堆栈跟踪

我尝试使用OkHttp和Picasso(遵循此答案)来缓存我从Firebase存储下载的图像的磁盘缓存。现在,该应用程序会给出异常和崩溃。我看过这些帖子:帖子1帖子2,但我没有找到任何相关的解决方案。我也试图清理和重建这个项目,但没有运气。

以下是 build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "social.com.networking.social.media.app"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            multiDexEnabled true
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'br.com.mauker.materialsearchview:materialsearchview:1.2.0'
    compile 'com.alirezaafkar:toolbar:1.1.1'
    compile 'com.github.mancj:MaterialSearchBar:0.3.5'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.slider:library:1.1.5@aar'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.google.firebase:firebase-core:10.0.1'
    compile 'com.google.firebase:firebase-ads:10.0.1'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    compile "com.google.firebase:firebase-auth:10.0.1"
    compile 'com.google.firebase:firebase-storage:10.0.1'
    compile 'com.google.firebase:firebase-crash:10.0.1'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.0.2'
    compile 'com.android.support:multidex:1.0.1'

    compile 'org.parceler:parceler-api:1.1.6'
    annotationProcessor 'org.parceler:parceler:1.1.6'


    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

全栈跟踪

Process: social.com.networking.social.media.app, PID: 28258
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/okhttp/OkHttpClient;
at com.squareup.picasso.OkHttpDownloader.defaultOkHttpClient(OkHttpDownloader.java:31)
at com.squareup.picasso.OkHttpDownloader.<init>(OkHttpDownloader.java:76)
at com.squareup.picasso.OkHttpDownloader.<init>(OkHttpDownloader.java:65)
at social.com.networkingsocialmediaapp.Global.onCreate(Global.java:17)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1018)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4991)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1555)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.squareup.okhttp.OkHttpClient" on path: DexPathList[[zip file "/data/app/social.com.networking.social.media.app-2/base.apk"],nativeLibraryDirectories=[/data/app/social.com.networking.social.media.app-2/lib/arm64, /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 com.squareup.picasso.OkHttpDownloader.defaultOkHttpClient(OkHttpDownloader.java:31)
at com.squareup.picasso.OkHttpDownloader.<init>(OkHttpDownloader.java:76)
at com.squareup.picasso.OkHttpDownloader.<init>(OkHttpDownloader.java:65)
at social.com.networkingsocialmediaapp.Global.onCreate(Global.java:17)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1018)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4991)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1555)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

Suppressed: java.lang.ClassNotFoundException: com.squareup.okhttp.OkHttpClient
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)
... 15 more

Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

编辑 1:正如Redman所说,我已经启用了MultiDex,但它仍然给出了相同的错误。根据这一点:developer.android.com/studio/build/multidex.html#keep,我需要决定在基本APK中哪些类是必需的。如何确定哪些类是必需的?


答案 1

Android Studio 2.3 及更高版本中,有 Instant Run 可能会影响您的代码。

禁用Instant Run

文件 - >设置 - >构建,执行,部署 - >即时运行

在我的情况下,它从运行时工作完美,但在从其他来源安装时崩溃Android Studio


答案 2

1)请从您的手机中卸载该应用程序

2)立即从安卓工作室重新安装应用程序

3)98%它将工作,否则清理项目并重新安装


推荐