OkHttp only works on Lollipop

2

The OkHttp 2.6.0 library does not work on versions prior to Android 5. In versions prior to Lollipop always throws the exception:

Exception

  

Caused by: java.lang.NoClassDefFoundError: com.squareup.okhttp.internal.Util                                                          at com.squareup.okhttp.OkHttpClient (OkHttpClient.java:58)

My build.gradle

apply plugin: 'com.android.application'

android {
  compileSdkVersion 23
  buildToolsVersion '23.0.2'
  defaultConfig {
    minSdkVersion 9
    targetSdkVersion 23
    versionCode 14
    versionName '1.6.7'
    multiDexEnabled true
  }
  signingConfigs {
    release {}
  }
  buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
  }
  packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/ASL2.0'
  }
  productFlavors {
  }
}

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile project(':number_picker_lib_2')

  compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
  compile 'org.codehaus.jackson:jackson-core-asl:1.9.13'
  compile 'com.squareup.okhttp:okhttp:2.6.0'
  compile 'com.github.machinarius:preferencefragment:0.1.1'
  compile 'com.android.support:appcompat-v7:23.1.0'
  compile 'com.android.support:support-v4:23.1.0'
  compile 'com.android.support:design:23.1.0'
  compile 'com.google.android.gms:play-services:8.3.0'
  compile 'com.google.android.gms:play-services-ads:8.3.0'
  compile 'com.google.android.gms:play-services-identity:8.3.0'
  compile 'com.google.android.gms:play-services-gcm:8.3.0'
  compile 'com.jakewharton:butterknife:6.1.0'
  compile 'de.hdodenhof:circleimageview:1.3.0'
}
    
asked by anonymous 06.12.2015 / 19:06

1 answer

1

The problem is that you stopped adding Okio , another library that OkHttp needs to work, according to the official documentation :

  

You'll also need Okio, which OkHttp uses for fast I / O and resizable   buffers. Download the latest JAR.

Add Okio to your build.gradle :

compile 'com.squareup.okio:okio:1.6.0'
    
08.12.2015 / 12:47