引起:java.lang.NoClassDefFoundError: Class not found using the boot class loader; 没有可用的堆栈跟踪

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41986851/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 23:51:16  来源:igfitidea点击:

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

javaandroidandroid-studioandroid-gradle-pluginokhttp

提问by Shubham Shukla

I tried using OkHttp and Picasso (following this answer) for disk caching of images that I was downloading from Firebase storage. Now, the app gives exceptions and crashes. I have seen these posts: post 1, post 2but I didn't find any relevant solutions. I also tried to clean and rebuild the project but had no luck.

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

Here is build.gradle:

这是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'

Full Stacktrace:

完整的堆栈跟踪

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

Edit 1:I have enabled MultiDex as Redman said but it still gives the same error. According to this: developer.android.com/studio/build/multidex.html#keep, I need to decide which classes are necessary in the base APK. How do I determine which classes are necessary?

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

采纳答案by Kishore Jethava

In Android Studio 2.3 and higher, There is Instant Runwhich may affect your code.

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

Disable Instant Run

禁用 Instant Run

File -> Settings -> Build, Execution, Deployment -> Instant Run

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

In my case it was working perfect when run from Android Studiobut crashing when install from other sources

在我的情况下,它在运行时运行良好,Android Studio但在从其他来源安装时崩溃

回答by Manohar Reddy

You may need to enable multidex, follow the guide from this

您可能需要启用 multidex,请按照此指南进行操作

https://developer.android.com/studio/build/multidex.html,for enabling multidex

https://developer.android.com/studio/build/multidex.html,用于启用 multidex

  defaultConfig {

    minSdkVersion 14
    targetSdkVersion 21

    multiDexEnabled true
}

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

回答by Kulasekar

1)Kindly uninstall the app from your mobile

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

2)Reinstall the app now from android studio

2)现在从android studio重新安装应用程序

3)98% it will work else clean the project and reinstall it again

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

回答by Zon

Try removing .gradlefolder from project.

尝试从项目中删除.gradle文件夹。

回答by Shamim Ahmad

My Code way compiling well on the device using USB cable, but when I was trying to install it using *.apk file it was breaking, so I unchecked the option File -> Settings -> Build, Execution, Deployment -> Instant Run, but now its working fine with *.apk file and starting breaking with USB install, the error message is in the attachec image, even if I press OK it doesn't work, when I try yo install it again the same error message appears.

我的代码方式使用 USB 电缆在设备上编译良好,但是当我尝试使用 *.apk 文件安装它时,它被破坏了,所以我取消选中选项File -> Settings -> Build, Execution, Deployment -> Instant Run,但是现在它可以与 *.apk 文件一起正常工作并开始破坏 USB 安装,错误消息在附件图像中,即使我按 OK 它也不起作用,当我再次尝试安装它时,会出现相同的错误消息。

enter image description here

在此处输入图片说明

回答by hepeng

I've also had this problem, and it's still not possible to turn off the instant run.Later, I found that I deleted all the files under the build-cache folder, and then clean the project.My directory is C:\Users\ HDB . Android \ built-cache.I hope I can help other people who encounter this bug.

我也遇到过这个问题,还是不能关掉instant run。后来发现把build-cache文件夹下的文件全部删除了,然后清理项目。我的目录是C:\Users \建屋局。Android\内置缓存。希望可以帮助其他遇到此错误的人。

回答by Kartikeya Kapparwan

This error also occurs because of the differences in libraries' version specification that can lead to runtime errors. Always use same versions of libraries in build.gradle.
For example:

由于库版本规范的差异可能导致运行时错误,也会发生此错误。始终在 build.gradle 中使用相同版本的库。
例如:

Use this:

用这个:

implementation 'com.google.android.gms:play-services-location:11.6.0'
implementation 'com.google.android.gms:play-services-auth:11.6.0'

Instead of:

代替:

implementation 'com.google.android.gms:play-services-location:15.0.0'
implementation 'com.google.android.gms:play-services-auth:11.6.0'

回答by Rezaul Karim

Just remove your project's build folder, then clean and run your application. This did the trick for me...

只需删除您项目的构建文件夹,然后清理并运行您的应用程序。这对我有用...

回答by Mayuresh Satao

For me this problem was solved by Disable Instant Run

对我来说,这个问题是通过禁用即时运行解决的

Just go to Preferences -> Build, Execution, Deployment -> Instant Run -> Disable the option

只需转到首选项 -> 构建、执行、部署 -> 即时运行 -> 禁用该选项

And restart the app

并重新启动应用程序

回答by kuhrusty

(I know this is an old question, but I came here looking for a solution to a similar problem.)

(我知道这是一个老问题,但我来这里是为了寻找类似问题的解决方案。)

I have a different answer to consider beforeyou exhaust all the other suggestions above: the ClassNotFoundException: YourParcelableClass error may not be the problem.In fact, it may not be aproblem.

您穷尽上述所有其他建议之前,我有一个不同的答案需要考虑:ClassNotFoundException: YourParcelableClass 错误可能不是问题所在。事实上,它可能不是一个问题。

I have an app which displays a screen of various content which is passed in as a Parcelable and rendered as HTML in a WebView; it was working great until I cleaned up the code, checked it in, checked out a clean new tree, and uninstalled & reinstalled the app on my phone. I started getting a blank screen; obviously that ClassNotFoundException in the log meant my content was not being unmarshalled correctly.

我有一个应用程序,它显示各种内容的屏幕,这些内容作为 Parcelable 传入并在 WebView 中呈现为 HTML;在我清理代码、签入、签出一棵干净的新树、卸载并重新安装手机上的应用程序之前,它一直运行良好。我开始出现空白屏幕;显然,日志中的 ClassNotFoundException 意味着我的内容没有被正确解组。

After at leastan hour of disabling Instant Run, rm -rf .gradle, Clean Project, Invalidate Caches & Restart, etc., etc., I started adding increasingly sanity-questioning logging until I figured out that I wasgetting my content from Intent.getParcelableExtra(); the blank screen appeared to be unrelated! (I still don't know why, but WebView.loadData()had stopped working, and had to be replaced with WebView.loadDataWithBaseURL().)

在禁用 Instant Run、Clean Project、Invalidate Caches & Restart 等至少一个小时后rm -rf .gradle,我开始添加越来越多的理智问题日志记录,直到我发现我Intent.getParcelableExtra(); 空白屏幕似乎无关!(我仍然不知道为什么,但WebView.loadData()已经停止工作,不得不用WebView.loadDataWithBaseURL().代替。)

Hopefully this saves someone else an hour of stupidity. If you see that ClassNotFoundException with your class' name, check to see whether your objects are still being unmarshalled correctly; they might be!

希望这可以为其他人节省一个小时的愚蠢。如果您看到 ClassNotFoundException 带有您的类名称,请检查您的对象是否仍在正确解组;他们可能是!