7

I'm trying to use FirebaseUI to retrieve a photo from Firebase Storage and show it directly in my imageview using Glide. In order to do that I've created a ModelLoader as shown in Firebase Documentation:

import com.bumptech.glide.Glide;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;
import com.firebase.ui.storage.images.FirebaseImageLoader;
import com.google.firebase.storage.StorageReference;

import java.io.InputStream;

@GlideModule
public class MyAppGlideModule extends AppGlideModule {
    @Override
    public void registerComponents(Context context, Glide glide, Registry registry) {
        // Register FirebaseImageLoader to handle StorageReference
        registry.append(StorageReference.class, InputStream.class,
                new FirebaseImageLoader.Factory());
    }
}

This file is inside my project folder so gradle should recognize it. The problem is, everytime I run the app and this line of code executes: Glide.with(context!!).load(reference).into(binding.imgPhoto) this error appears:

W/Glide: Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored
E/GlideExecutor: Request threw uncaught throwable
    com.bumptech.glide.Registry$NoModelLoaderAvailableException: Failed to find any ModelLoaders registered for model class: class com.google.firebase.storage.StorageReference
        at com.bumptech.glide.load.model.ModelLoaderRegistry.getModelLoaders(ModelLoaderRegistry.java:77)
        at com.bumptech.glide.Registry.getModelLoaders(Registry.java:585)
        at com.bumptech.glide.load.engine.DecodeHelper.getLoadData(DecodeHelper.java:207)
        at com.bumptech.glide.load.engine.DecodeHelper.getCacheKeys(DecodeHelper.java:224)
        at com.bumptech.glide.load.engine.ResourceCacheGenerator.startNext(ResourceCacheGenerator.java:44)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:276)
        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393)

What is happening? I've created the Loader, Invalidated Caches, Restarted, and the problem still isn't solved...

André Nogueira
  • 3,363
  • 3
  • 10
  • 16

1 Answers1

12

You need to create a class (e.g MyAppGlideModule) that extends AppGlideModule and use GlideApp.with... instead of Glide.with... check this link for full explanation

The class MyAppGlideModule can live anywhere in your source directory and is processed by the Glide annotation processor at compile time in order to create the GlideApp class.

For kotlin:

@GlideModule
class AppGlide: AppGlideModule(){

    override fun registerComponents(
        context: android.content.Context,
        glide: Glide,
        registry: Registry
    ) {
        super.registerComponents(context, glide, registry)
        registry.append(
            StorageReference::class.java, InputStream::class.java,
            FirebaseImageLoader.Factory()
        )

    }
}
Ivan Lopes
  • 148
  • 3
  • 12
  • 3
    Thank you! I really wish the developer documents mentioned this instead of just putting a single function without much additional info on https://firebase.google.com/docs/storage/android/download-files – mcy Dec 23 '20 at 10:13
  • 1
    Don't know why, but using Glide instead of GlideApp works for me. – Tayyab Mazhar Apr 25 '21 at 15:32