ndeokar ndeokar - 4 months ago 55
Android Question

Glide with okhttp3 integration java.lang.NoClassDefFoundError

I am using okhttp3 with glide so I have added the integration part as well.

compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.github.bumptech.glide:okhttp-integration:1.4.0@aar'


I have even enabled multidex support using

compile 'com.android.support:multidex:1.0.1'


and adding this to application class

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


Here is full stack trace -

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/okhttp/OkHttpClient;
at com.bumptech.glide.integration.okhttp.OkHttpUrlLoader$Factory.getInternalClient(OkHttpUrlLoader.java:30)
at com.bumptech.glide.integration.okhttp.OkHttpUrlLoader$Factory.<init>(OkHttpUrlLoader.java:41)
at com.bumptech.glide.integration.okhttp.OkHttpGlideModule.registerComponents(OkHttpGlideModule.java:31)
at com.bumptech.glide.Glide.get(Glide.java:157)
at com.bumptech.glide.RequestManager.<init>(RequestManager.java:62)
at com.bumptech.glide.RequestManager.<init>(RequestManager.java:53)
at com.bumptech.glide.manager.RequestManagerRetriever.supportFragmentGet(RequestManagerRetriever.java:198)
at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:104)
at com.bumptech.glide.Glide.with(Glide.java:644)
at com.skcsllp.mutterfly.activities.EditProfileActivity.onCreate(EditProfileActivity.java:76)
at android.app.Activity.performCreate(Activity.java:6100)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)


Caused by: java.lang.ClassNotFoundException: Didn't find class "com.squareup.okhttp.OkHttpClient" on path: DexPathList[[dex file
"/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-support-annotations-23.2.1_711eea7d990a3279fc66c06b239bf29196aabc02-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_9-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_8-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_7-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_6-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_5-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_4-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_3-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_2-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_1-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_0-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-okio-1.6.0_4cb2265fa47e13dbef896857be4ee851d4d21b93-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-okhttp-3.2.0_c46370073bf914e884c23455554d5f56e9b15f17-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-internal_impl-23.2.1_945649fcb49395f2024bfee914abcd2b33619e3f-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-gson-2.2.4_d0ce76b63ce905fbab3c5d385c8e1b8692010f19-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-glide-3.6.1_362f6061e938ba7d3e28c67a4832a9a19bdf24aa-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-com.google.android.gms-play-services-gcm-7.8.0_defd878a1ea68768e6e678ca0946f67a973b8929-classes.dex",


this is config for build

productFlavors {
// Define separate dev and prod product flavors.
dev {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion 15
}
}


I could not figure out what's wrong with dex process.

EDIT

Everything works great if i simply remove the integration part from the build.gradle

compile 'com.github.bumptech.glide:okhttp-integration:1.4.0@aar'

Answer

No need for multidex unless you have too many methods.

Decide if you're using okhttp (v2) or okhttp3 and update your code accordingly:

compile 'com.github.bumptech.glide:okhttp-integration:1.4.0@aar'
compile 'com.squareup.okhttp:okhttp:2.7.5'

or

compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'
compile 'com.squareup.okhttp3:okhttp:3.2.0'

Read https://github.com/bumptech/glide/wiki/Integration-Libraries for more details.

(Source: https://github.com/bumptech/glide/issues/1158#issuecomment-215007390)

Comments