You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Glide无法加载Firebase Storage中图片的问题求助

Solution for Loading Firebase Storage Images with Glide 4.6.1 & Firebase 11.8.0

Hey there, I’ve run into this exact headache with Glide 4.x and Firebase Storage before—let me walk you through the fix step by step, since the old Firebase docs don’t account for Glide 4’s breaking changes.

First, Understand the Core Issues

Glide 4.x completely removed the .using() method that the older Firebase docs relied on, and raw gs:// URLs aren’t natively recognized by Glide. We’ll fix both with Firebase’s official Glide integration, no manual URL conversion needed.

Step 1: Add the FirebaseUI Storage-Glide Dependency

First, make sure you have the FirebaseUI dependency that bridges Glide and Firebase Storage in your app-level build.gradle (match the version to your Firebase SDK 11.8.0):

dependencies {
    // ... your existing dependencies
    implementation 'com.firebaseui:firebase-ui-storage:11.8.0'
}

Step 2: Create a Custom AppGlideModule

Glide 4.x uses modules to register custom loaders instead of the old .using() method. Create a new class to register Firebase’s image loader:

import android.content.Context;
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 Firebase Storage's custom loader with Glide
        registry.append(StorageReference.class, InputStream.class,
                new FirebaseImageLoader.Factory());
    }
}

Pro tip: The @GlideModule annotation is critical here—Glide will auto-generate a GlideApp class during compilation, which we’ll use instead of the regular Glide class. If you don’t see it right away, do a clean rebuild of your project.

Step 3: Load Images Directly from StorageReference

Now you can load your gs:// reference directly with GlideApp—no messy URL conversions, and Firebase won’t redirect you back to gs:// format:

// Get your StorageReference (either from the gs:// URL or FirebaseStorage instance)
StorageReference imageRef = FirebaseStorage.getInstance().getReferenceFromUrl("gs://bucket/images/stars.jpg");

// Load the image into your ImageView
GlideApp.with(context)
        .load(imageRef)
        .placeholder(R.drawable.placeholder_image) // Optional: Add a placeholder
        .error(R.drawable.error_image) // Optional: Add an error fallback
        .into(yourImageView);

Why This Works

  • The FirebaseUI integration handles the gs:// reference internally, so you don’t have to fuss with converting it to an HTTP URL (which eliminates the redirect issue you ran into).
  • The AppGlideModule registers Firebase’s custom loader with Glide 4.x, replacing the deprecated .using() method.

Quick Troubleshooting

  • If GlideApp isn’t showing up, clean and rebuild your project—Glide generates this class automatically, but it might take a compile pass.
  • Double-check your Firebase Storage rules to make sure read access is allowed for the image you’re trying to load (this is a super common oversight!).

内容的提问来源于stack exchange,提问作者kac5a

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:20:34