Shubham Shukla
Shubham Shukla

Reputation: 998

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

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 2 but I didn't find any relevant solutions. I also tried to clean and rebuild the project but had no luck.

Here is 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?

Upvotes: 18

Views: 49078

Answers (12)

Faisal Amin
Faisal Amin

Reputation: 91

Add this to your app-level Gradle in android tag

buildFeatures {
    dataBinding true
}

Upvotes: 0

Wild Will
Wild Will

Reputation: 21

I found another "answer" to the issue. I was getting the same error message using Android Studio 3.3.2. I decided to clear ALL breakpoints. On the breakpoints dialog there are two "permanant" options, Java Exception Breakpoints and Exception Breakpoints.   I had them both checked, by accident probably.   When I cleared them and other break points I could run under Debug mode. Now that debug is running I can add break points as long as those are not checked!

Upvotes: 0

kuhrusty
kuhrusty

Reputation: 151

(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 before you exhaust all the other suggestions above: the ClassNotFoundException: YourParcelableClass error may not be the problem. In fact, it may not be a problem.

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.

After at least an 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 was getting 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().)

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!

Upvotes: 1

Vivek
Vivek

Reputation: 599

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

Upvotes: 0

Rezaul Karim
Rezaul Karim

Reputation: 1349

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

Upvotes: 5

Kartikeya Kapparwan
Kartikeya Kapparwan

Reputation: 21

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:

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'

Upvotes: 0

Kishore Jethava
Kishore Jethava

Reputation: 6834

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

Disable Instant Run

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

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

Upvotes: 62

hepeng
hepeng

Reputation: 1

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.

Upvotes: 0

Shamim Ahmad
Shamim Ahmad

Reputation: 808

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.

enter image description here

Upvotes: 2

Zon
Zon

Reputation: 19880

Try removing .gradle folder from project.

Upvotes: 1

Kulasekar
Kulasekar

Reputation: 507

1)Kindly uninstall the app from your mobile

2)Reinstall the app now from android studio

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

Upvotes: 10

Manohar
Manohar

Reputation: 23394

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

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

  defaultConfig {

    minSdkVersion 14
    targetSdkVersion 21

    multiDexEnabled true
}

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

Upvotes: 7

Related Questions