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
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
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'
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
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:)
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);
}
});
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'