12

There are tons of duplicated answers I had tried almost all of them but I am still not able to use Firebase storage image with Glide.

First of all I am using docs

    FirebaseStorage storage  = FirebaseStorage.getInstance();
    StorageReference storageRef = storage.getReference();
    StorageReference pathReference = storageRef.child("sorular/1.jpg");

   // ImageView in your Activity
   ImageView imageView = rootView.findViewById(R.id.imageView);

   // Load the image using Glide
   Glide.with(this /* context */)
        .using(new FirebaseImageLoader()) // Cannot resolve method 'using
        .load(pathReference)
        .into(imageView);

if I clean the .using part of Glide, logcat it gives this error:

E/GlideExecutor: Request threw uncaught throwable com.bumptech.glide.Registry$NoModelLoaderAvailableException: Failed to find any ModelLoaders for model: gs://123...appspot.com/sorular/1.jpg
at com.bumptech.glide.Registry.getModelLoaders(Registry.java:227)
at com.bumptech.glide.load.engine.DecodeHelper.getLoadData(DecodeHelper.java:179) at com.bumptech.glide.load.engine.DecodeHelper.getCacheKeys(DecodeHelper.java:197) at com.bumptech.glide.load.engine.ResourceCacheGenerator.startNext(ResourceCacheGenerator.java:41) at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:282) at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:249) at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:222)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761)
at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:347)

So how can use firebase storage images in my android app in a best way?

also this my build gradle dependencies:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support:palette-v7:27.0.2'
    implementation "com.android.support:cardview-v7:27.0.2"
    implementation "com.android.support:recyclerview-v7:27.0.2"
    implementation "com.android.support:support-v4:27.0.2"
    implementation 'com.android.support:design:27.0.2'

    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.github.florent37:materialviewpager:1.2.3'


    implementation 'com.google.firebase:firebase-database:11.8.0'
    implementation 'com.google.firebase:firebase-storage:11.8.0'
    implementation 'com.firebaseui:firebase-ui-storage:2.0.1'
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
mehmet
  • 1,558
  • 5
  • 30
  • 41

7 Answers7

24

Change this:

 implementation 'com.firebaseui:firebase-ui-storage:2.0.1'

to this:

  implementation 'com.firebaseui:firebase-ui-storage:3.2.1'

According to the Glide docs:

using()

The using() API was removed in Glide 4 to encourage users to register their components once with a AppGlideModule to avoid object re-use. Rather than creating a new ModelLoader each time you load an image, you register it once in an AppGlideModule and let Glide inspect your model (the object you pass to load()) to figure out when to use your registered ModelLoader.

To make sure you only use your ModelLoader for certain models, implement handles() as shown above to inspect each model and return true only if your ModelLoader should be used.

using() was removed from Glide 4.

To Solve this, you need to do this: To load an image from a StorageReference, first register an AppGlideModule:

  @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());
  }
}

Once you have created an AppGlideModule class and done a clean build, you can use GlideApp to load a StorageReference into an ImageView:

// Reference to an image file in Cloud Storage
StorageReference storageReference = ...;

// ImageView in your Activity
ImageView imageView = ...;

// Download directly from StorageReference using Glide
// (See MyAppGlideModule for Loader registration)
GlideApp.with(this /* context */)
        .load(storageReference)
        .into(imageView);

more info here: https://github.com/firebase/FirebaseUI-Android/tree/master/storage

Community
  • 1
  • 1
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • Are you sure? because I ve changed but still ".using(new FirebaseImageLoader())" cannot resolved. in my opinion the problem is about Glide – mehmet Feb 13 '18 at 08:37
  • yes https://github.com/firebase/FirebaseUI-Android/issues/731, https://github.com/firebase/FirebaseUI-Android/pull/802. The method `using(..)` is for glide 4.0 versions and in the github page in the end they added support for glide 4.0 in firebaseui version 3.0 – Peter Haddad Feb 13 '18 at 08:38
  • use this glide library `compile 'com.github.bumptech.glide:glide:4.0.0-RC1'` @mehmet After changing then resync, rebuild, and clean – Peter Haddad Feb 13 '18 at 08:41
  • did you try the above? And what glide version are you using? – Peter Haddad Feb 13 '18 at 09:01
  • compile 'com.github.bumptech.glide:glide:4.0.0-RC1' implementation 'com.firebaseui:firebase-ui-storage:2.0.1' it is still same error Failed to find any ModelLoaders for model: and if (use firebase ui 3.2.1 app not openning. – mehmet Feb 13 '18 at 09:06
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/165028/discussion-between-mehmet-and-peter-haddad). – mehmet Feb 13 '18 at 09:11
  • Im getting the same error "Failed to find any ModelLoaders for model" – glupeksha Jun 28 '18 at 18:28
  • i am getting this com.bumptech.glide.Registry$NoModelLoaderAvailableException: Failed to find any ModelLoaders for model: com.google.firebase.auth.internal.zzl@1ea5795 – Vinit Poojary Mar 26 '19 at 08:46
  • Glide.with(context) .load(storageReference) .into(productViewHolder.productImage); not working with reference – Sonali Kale Jan 18 '20 at 09:00
  • @mehmet ensure you are implement `com.github.bumptech.glide:compiler:4.12.0` – fahrizal89 Mar 17 '22 at 02:48
6

I Know im bit late but it might help some of you. Use both of these in app build.gradle.

implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0' //For Kotlin You should use kapt instead of annotationProcessor though.

Then add This Class:

@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());
    }
}

 GlideApp.with(getActivity()).load(storageReference).into(profileImg);

At last you need to go to File-> Invalidate Cache and Restart Done:)

Xenolion
  • 12,035
  • 7
  • 33
  • 48
Vikash Sharma
  • 539
  • 8
  • 13
  • 2
    "At last you need to go to File-> Invalidate Cache and Restart "- save my 2 days!!! THANKS!!!! – Vaha Feb 06 '20 at 15:57
4

If you've uploaded little images for icons on to your Firebase storage, get rid off glide and that "model". It makes a lot of changes on its git. So your code should look like:

   StorageReference referenseLcl = FirebaseStorage.getInstance().getReference();
                StorageReference islandRefLcl = referenseLcl.child(userLcl.getImageIconPath());
                final long ONE_MEGABYTE = 1024 * 1024;
                islandRefLcl.getBytes(ONE_MEGABYTE).addOnSuccessListener(bytesPrm -> {
                    Bitmap bmp = BitmapFactory.decodeByteArray(bytesPrm, 0, bytesPrm.length);
                    imageOfUser.setImageBitmap(bmp);
                }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception exception) {
                        imageOfUser.setImageResource(R.mipmap.ic_launcher);
                    }
                });
CodeToLife
  • 3,672
  • 2
  • 41
  • 29
  • Person who used this method: We need to manage cache if we're not using Glide. [Glide Caching](https://bumptech.github.io/glide/doc/caching.html) – Yogi Dec 02 '20 at 02:25
2

As for Glide 4.6.1 you can't use .using(new FirebaseImageLoader())

I am force to downgrade to

implementation 'com.github.bumptech.glide:glide:3.8.0'

and Firebase UI implementation'com.firebaseui:firebase-ui-storage:2.0.1'

GGWP
  • 1,111
  • 2
  • 12
  • 24
1

The answers above didn't help me.

I was missing this in my gradle.

annotationProcessor 'com.github.bumptech.glide:compiler:4.x' //For Kotlin advice use kapt instead of annotationProcessor

The best docs I have found are here

Xenolion
  • 12,035
  • 7
  • 33
  • 48
nburn42
  • 697
  • 7
  • 25
0

I am using kotlin.

in my case, because I still use annotation processor like this

annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

I should use:

kapt 'com.github.bumptech.glide:compiler:4.11.0'

sarah
  • 3,819
  • 4
  • 38
  • 80
0

Kotlin implementation of GlideModule :

@GlideModule
class GlideModule : AppGlideModule() {

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

}

Don't forget to import the correct dependencies :

dependencies {
    def glide_version = "4.12.0"
    implementation "com.github.bumptech.glide:glide:$glide_version"
    kapt "com.github.bumptech.glide:compiler:$glide_version"
}
Julian Paul
  • 162
  • 1
  • 2