how to solve java.lang.NoClassDefFoundError: okio.Okio?

android picture android · May 2, 2016 · Viewed 11.7k times · Source

I have an app that work very well but some times when I add some class and code to my program my app crashes. In my logcat error is for this:

 8871-8929/com.example.first E/AndroidRuntime﹕ FATAL EXCEPTION: pool-4-thread-1
java.lang.NoClassDefFoundError: okio.Okio
    at com.squareup.okhttp.internal.http.HttpConnection.<init>    (HttpConnection.java:90)
    at com.squareup.okhttp.Connection.connectSocket(Connection.java:208)
    at com.squareup.okhttp.Connection.connect(Connection.java:172)
    at com.squareup.okhttp.Connection.connectAndSetOwner(Connection.java:367)
    at com.squareup.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:128)
    at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:328)
    at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:245)
    at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:438)
    at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:389)
    at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:233)

My gradle:

dependencies {
 compile fileTree(dir: 'libs', include: ['*.jar'])
 compile 'com.android.support:support-v4:23.1.+'
 compile 'com.google.android.gms:play-services:3.2.+'
 compile 'net.hockeyapp.android:HockeySDK:3.6.+'
 compile 'com.googlecode.mp4parser:isoparser:1.0.+'
 compile 'com.android.support:appcompat-v7:23.1.0'
 compile 'com.android.support:design:23.1.1'
 compile 'com.android.support:cardview-v7:23.1.0'
 compile 'com.android.support:recyclerview-v7:23.0.1'
 compile 'com.github.bumptech.glide:glide:+'
 compile 'com.nineoldandroids:library:2.4.+'
  compile 'com.koushikdutta.ion:ion:2.+'
 compile 'de.greenrobot:eventbus:2.4.0'
 compile 'com.github.dmytrodanylyk.circular-progress-button:library:1.1.3'
 compile 'com.theartofdev.edmodo:android-image-cropper:1.0.+'
 compile 'com.squareup.picasso:picasso:2.5.2'
 compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.5'
 compile 'com.github.rahatarmanahmed:circularprogressview:2.4.0'
 compile 'com.makeramen:roundedimageview:2.1.2'
 compile 'com.squareup.okio:okio:1.6.0'
}

Answer

Alexandre G picture Alexandre G · Oct 21, 2016

Perhaps you are crossing the 65K method limit, and have the multiDexEnabled = true, but haven't finished setting up multidexing correctly?

Need to add this if you haven't:

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

and

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

to class extending application

check full guide for details: https://developer.android.com/studio/build/multidex.html#avoid