How to set OkHttpClient for glide

since glide 4.0.0 it has changed a little bit.

first of all GlideModule is deprecated and you need to use AppGlideModule if you are developing an application and LibraryGlideModule for library development. you need to use @GlideModule above your custom AppGlideModule class.

secondly there is no register() method in Glide object any more.

and finally okhttp3 will use a builder.

it’ll be like below for apps:

    @GlideModule
    private class CustomGlideModule extends AppGlideModule {

       @Override
       public void registerComponents(Context context, Glide glide, Registry registry) {
           OkHttpClient client = new OkHttpClient.Builder()
                   .readTimeout(15, TimeUnit.SECONDS)
                   .connectTimeout(15, TimeUnit.SECONDS)
                   .build();

       OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(client);

           glide.getRegistry().replace(GlideUrl.class, InputStream.class, factory);
       }
   }

you’ll need to have all these dependency with the exact versions in your app gradle file:

 compile "com.squareup.okhttp3:okhttp:3.8.1"
    compile 'com.github.bumptech.glide:glide:4.0.0'
    compile ('com.github.bumptech.glide:okhttp3-integration:4.0.0'){
        exclude group: 'glide-parent'
    }

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)