Basheer AL-MOMANI Basheer AL-MOMANI - 1 year ago 541
Android Question

Network Inspection in Stetho with Glide and okhttp3

how to Combine Glide and Stetho to debug image loading system using okhttp3

I did the following

1.Added the dependancies

compile 'com.facebook.stetho:stetho:1.3.1'
compile 'com.facebook.stetho:stetho-okhttp3:1.3.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
// Glide's OkHttp3 Integration
compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'
compile 'com.squareup.okhttp3:okhttp:3.2.0'

1.Added the initialization

public class MyApplication extends Application {

public void onCreate() {


3.add glide config to use okhttp3

* Created by Arnaud Camus Copied by MOMANI on 2016/04/15.
public class StethoOkHttpGlideModule implements GlideModule {
public void applyOptions(Context context, GlideBuilder builder) { }

public void registerComponents(Context context, Glide glide) {
okhttp3.OkHttpClient client = new okhttp3.OkHttpClient();
client.networkInterceptors().add(new com.facebook.stetho.okhttp3.StethoInterceptor());
glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));

4.added the
metadata tag in

<meta-data android:name=""
android:value="GlideModule" />

5.Glide loadimg images line

Glide.with(((ViewHolderSmall) holder).imageView.getContext())
// .diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(((ViewHolderSmall) holder).imageView);

when I open chrome Developer tool
Resources Tab
works perfectly but
network tab

why? where is my mistake? and is it recommended to use
with Glide? and how how to connect it without using okhttp3

any duplication or links would help

Answer Source

Re: is it recommended to use okhttp3 with Glide?

Yes, this is the way to go for OkHttp integration.

Re: why? where is my mistake?

This is likely needed because the built-in GlideModule may be overwriting your intercepted client (there's no defined ordering between GlideModule execution). Consider the following from the wiki:

When overriding default behaviour make sure your custom GlideModule is registered in the manifest and the default one is excluded. Exclusion may mean removing the corresponding metadata from the manifest or using the jar dependency instead of the aar one. -- Overriding default behaviour - Glide Wiki

Based on Conflicting GlideModules - Glide Wiki: remove @aar from the okhttp3-integration dependency, or add to manifest:

<meta-data android:name="com.bumptech.glide.integration.okhttp3.OkHttpGlideModule" tools:node=”remove” />

Also make sure you're not fooled by the cache: .diskCacheStrategy(NONE).skipMemoryCache(true); you can remove this as soon as you see the requests as you expect them to.

OkHttp3 changed the API client.networkInterceptors() is not writable any more:

okhttp3.OkHttpClient client = new okhttp3.OkHttpClient.Builder()
            .addNetworkInterceptor(new com.facebook.stetho.okhttp3.StethoInterceptor())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download