how to use GlideModule on Glide 4?

I recently update my app to use Glide 4, to be precise, Glide 4.2.0. gradle:

compile 'com.github.bumptech.glide:glide:4.2.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.2.0'
compile ('com.github.bumptech.glide:okhttp3-integration:4.2.0'){
    exclude group: 'glide-parent'

in manifest:


GlideModule class:

public class MyGlideModule extends AppGlideModule {

    public void registerComponents(Context context, Glide glide, Registry registry) {
        OkHttpClient client = new OkHttpClient.Builder()
                .readTimeout(30, TimeUnit.SECONDS)
                .writeTimeout(30, TimeUnit.SECONDS)
                .connectTimeout(30, TimeUnit.SECONDS)

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

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

how I use glide inside an adapter:

        RequestOptions myOptions = new RequestOptions()


with these code, when I run it I got error:

java.lang.RuntimeException: Expected instanceof GlideModule, but found: [my app package][email protected]
  at com.bumptech.glide.module.ManifestParser.parseModule(
  at com.bumptech.glide.module.ManifestParser.parse(
  at com.bumptech.glide.Glide.initializeGlide(
  at com.bumptech.glide.Glide.checkAndInitializeGlide(
  at com.bumptech.glide.Glide.get(
  at com.bumptech.glide.Glide.getRetriever(
  at com.bumptech.glide.Glide.with(
  at [adapter line where I implement Glide]

how can I use MyGlideModule ?

enter image description here

try this

Glide 4.0 need not have declare "GlideModule" in AndroidMinifest.xml. You just need to following steps:

  1. YourGlideModule extends AppGlideModule, you can override function applyOptions in the YourGlideModule class.
  2. You should make project in "android studio -> build -> make project", it will generate the GlideApp class.
  3. Use the GlideApp such as "GlideApp.with(this).load(imgUrl).into(glide_test_iv1)"