2

I've read this question Android http connecting with OkHttp Dont work and NoClassDefFoundError for OkHttpClient but it hasn't solved my problem . Still am facing java.lang.NoClassDefFoundError: com.squareup.okhttp.OkHttpClient this error , i have added both okhttp-3.4.1.jar and okio-1.10.0.jar, also i have tried to add OkHttp dependency compile 'com.squareup.okhttp3:okhttp:3.4.1' but my Android Studio says that it cannot Resolve it. so ma really stuck what can i do for this. Am using Android Studio Version 1.5.1

Below is my error in the logcat

09/pixsor.app.huzykamz.pixoradmin E/AndroidRuntime: FATAL EXCEPTION: main
Process: pixsor.app.huzykamz.pixoradmin, PID: 14209
java.lang.NoClassDefFoundError: com.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 pixsor.app.huzykamz.pixoradmin.PixorAdmin.onCreate(PixorAdmin.java:21)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4328)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)

The Error is brought on this line;

builder.downloader(new OkHttpDownloader(this,Integer.MAX_VALUE));

In this code Below;

 FirebaseDatabase.getInstance().setPersistenceEnabled(true);
            Picasso.Builder builder = new Picasso.Builder(this);
            builder.downloader(new OkHttpDownloader(this,Integer.MAX_VALUE));
            Picasso built = builder.build();
            built.setIndicatorsEnabled(false);
            built.setLoggingEnabled(true);
            Picasso.setSingletonInstance(built);

This is my gradle File.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
     //   vectorDrawables.useSupportLibrary = true
        applicationId "pixsor.app.huzykamz.pixoradmin"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

       // multiDexEnabled true
    }
    buildTypes {
        release {
           // minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}




dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.google.firebase:firebase-core:9.4.0'
    compile 'com.google.firebase:firebase-database:9.4.0'
    compile 'com.google.firebase:firebase-crash:9.4.0'
    compile 'com.google.firebase:firebase-auth:9.4.0'
    compile 'com.google.firebase:firebase-storage:9.4.0'
    compile 'com.android.support:cardview-v7:23.0.+'
    compile 'com.android.support:recyclerview-v7:23.0.+'
    compile 'com.firebaseui:firebase-ui:0.4.3'

}
apply plugin: 'com.google.gms.google-services'

When i try to add an OkHttp dependency this is what happens enter image description here

So please help me out ...

Community
  • 1
  • 1
  • 1
    can you post both your `build.gradle` files? – Bartek Lipinski Oct 03 '16 at 08:19
  • pls provide your `build.gradle` – user1140237 Oct 03 '16 at 08:21
  • I have editted my question guys –  Oct 03 '16 at 08:25
  • I would encourage the use of the `compile` line instead of manually adding JAR files – OneCricketeer Oct 03 '16 at 08:27
  • @cricket_007 , yah i tried that , but android studio says , it cannot resolve it , why is that happening –  Oct 03 '16 at 08:29
  • Not sure, really since [OkHttp3 has that class](https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.html). I see `Picasso`... What version of that do you have? – OneCricketeer Oct 03 '16 at 08:32
  • Picasso version is `picasso-2.5.2.jar` , even picasso am using a jar file –  Oct 03 '16 at 08:34
  • @cricket_007, i have editted my question , check out the error i get when i add a dependency of OkHttp, when i aslo disable the offline mode it doesn;t work, man why is this like this , even my Repository is up-to-date –  Oct 03 '16 at 08:40
  • I think the fact that you have overlapping `okhttp` libraries, it is confused. Your error, is `at com.squareup.picasso`, so that would be a Picasso problem. If you just use the `compile` line for that, it should download the necessary dependencies needed for Picasso. Also, delete any competing Jar files in the libs folder – OneCricketeer Oct 03 '16 at 08:43
  • I have removed Picasso jar file , and inserted the its dependency in the gradle , it worked fine , but still for OkHttp is;nt working , what if i reduce it from that version –  Oct 03 '16 at 08:49
  • Oooh gosh i also reduced it to compile `'com.squareup.okhttp3:okhttp:2.5.0'` but it's bringing the same issue , for sure this error is really hectic –  Oct 03 '16 at 08:52
  • please help me @cricket_007 –  Oct 03 '16 at 08:55
  • I'd recommend grabbing the latest versions of both. OkHttp is at `3.4.1` and Picasso is at `2.5.2`. Personally, I don't use OkHttp, so if you only need Picasso, I can tell you that it isn't needed. Other than that, check if `jcenter` is the repository set in your gradle file and that you are not having network connection problems to [BinTray](https://bintray.com/bintray/jcenter) – OneCricketeer Oct 03 '16 at 09:01
  • Yeah jcenter() is set in my repository , let me try cleaning the project @cricket_007 –  Oct 03 '16 at 09:06
  • @cricket_007 , it has worked finally what i did was to reduce the OkHttp library to compile `'com.squareup.okhttp:okhttp:2.4.0'` , and also turning off the offline mode of my android studio –  Oct 03 '16 at 09:12
  • Yes, turning off offline mode would cause dependencies to start resolving :) – OneCricketeer Oct 03 '16 at 09:14

3 Answers3

4

Switch off the Offline Mode of your Android Studio , then try to add this dependency below in your gradle file.

I recommend you to use dependencies rather than jar files.

compile 'com.squareup.okhttp:okhttp:2.4.0'

Then Clean , Rebuild and Run your project

Lutaaya Huzaifah Idris
  • 3,596
  • 8
  • 38
  • 77
0

Check your manifest file, you must declare all your activity class in your manifest file...

0

I had a similar issue with Firebase 9.4.0, I had to wind back to 9.0.0 which resolved it, not a solution but maybe a temp fix?

GordonW
  • 1,120
  • 2
  • 16
  • 36
  • but this problem is on OkHttp not Firebase , may be try to explain it more –  Oct 03 '16 at 08:58
  • Its caused by conflicting dependency between Firebase and OKhttp. You went the other way you wound back Okhttp to an earlier version (I think going from version 3.x to verison 2.x now from what I can see in accepted answer). I required okhttp version 3.x so wound back Firebase to an earlier version without the conflicting dependency. – GordonW Oct 03 '16 at 09:52