Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glide gradle not recognizing ModelLoader

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...

like image 219
André Nogueira Avatar asked Feb 26 '20 11:02

André Nogueira


1 Answers

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()
        )

    }
}
like image 102
Ivan Lopes Avatar answered Oct 12 '22 12:10

Ivan Lopes