Class not found exception com.squareup.okhttp.logging.HttpLoggingInterceptor

Even after adding the dependencies and importing the class, I get java.lang.NoClassDefFoundError: com.squareup.okhttp.logging.HttpLoggingInterceptor.

Can anybody help?

Gradle Build File

apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "xyz" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" multiDexEnabled = true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } repositories { mavenCentral() } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:support-v4:23.1.1' compile 'com.google.code.gson:gson:2.4' compile 'com.android.support:design:23.1.1' compile 'com.android.support:cardview-v7:23.1.1' compile 'com.google.android.gms:play-services:8.3.0' compile 'com.facebook.android:facebook-android-sdk:4.1.0' compile 'com.android.support:recyclerview-v7:23.1.1' compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.jakewharton:butterknife:7.0.1' compile 'com.squareup.retrofit:retrofit:2.0.0-beta2' compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2' compile 'com.squareup.okhttp:logging-interceptor:2.6.0' } 
+4
source share
3 answers

In my case, I found that the versions of the okhttp3 and okhttp3: logging-interceptor dependencies should exactly match. For example:

 ... compile 'com.squareup.retrofit2:converter-gson:2.1.0' compile 'com.squareup.okhttp3:okhttp:3.4.1' compile 'com.squareup.okhttp3:logging-interceptor:3.4.1' ... 
+6
source

There may be a compatibility issue with the modification.

try:

compile 'com.squareup.okhttp: logging-interceptor: 2.5.0'

This post may be helpful.

Application Error on HttpLoggingInterceptor

+1
source

It can also be associated with multidex true in build.gradle (yes, it seems that some devices have problems with applications with multiple applications (read, Samsung ))

If this is your case, disable this flag and rebuild the project. Consider using

 minifyEnabled true shrinkResources true 

to reduce apk size. If it's still too big, this is really weird and bad news, but there are some methods to put your apk in the diet .

0
source

Source: https://habr.com/ru/post/1238394/


All Articles