bumptech/glide · error · IllegalStateException
Package name for {source} is null or empty
Error message
Package name for {source} is null or empty What it means
IllegalStateException thrown by ResourceDrawableDecoder.decode() when source.getAuthority() returns null or empty. The authority segment of an android.resource:// URI must contain the target package name so Glide can locate the resources.
Source
Thrown at library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java:75
private final Context context;
public ResourceDrawableDecoder(Context context) {
this.context = context.getApplicationContext();
}
@Override
public boolean handles(@NonNull Uri source, @NonNull Options options) {
String scheme = source.getScheme();
return scheme != null && scheme.equals(ContentResolver.SCHEME_ANDROID_RESOURCE);
}
@Nullable
@Override
public Resource<Drawable> decode(
@NonNull Uri source, int width, int height, @NonNull Options options) {
String packageName = source.getAuthority();
if (TextUtils.isEmpty(packageName)) {
throw new IllegalStateException("Package name for " + source + " is null or empty");
}
Context targetContext = findContextForPackage(source, packageName);
@DrawableRes int resId = findResourceIdFromUri(targetContext, source);
// Only use the provided theme if we're loading resources from our package. We can't get themes
// from other packages and we don't want to use a theme from our package when loading another
// package's resources.
Theme theme =
Preconditions.checkNotNull(packageName).equals(context.getPackageName())
? options.get(THEME)
: null;
Drawable drawable =
theme == null
? DrawableDecoderCompat.getDrawable(context, targetContext, resId)
: DrawableDecoderCompat.getDrawable(context, resId, theme);
return NonOwnedDrawableResource.newInstance(drawable);
}
@NonNullView on GitHub (pinned to eb14a895d8)
Solutions
- Build resource Uris with the documented form: android.resource://<package>/<type>/<name> or android.resource://<package>/<resId>.
- Use ResourceLoader or the integer-resId overload of Glide (Glide.with(ctx).load(R.drawable.foo)) instead of hand-building Uris.
- Validate Uri authority before passing to Glide.
Example fix
// before
Uri uri = Uri.parse("android.resource/" + resId); // missing authority
Glide.with(ctx).load(uri).into(img);
// after
Uri uri = Uri.parse("android.resource://" + ctx.getPackageName() + "/" + resId);
Glide.with(ctx).load(uri).into(img); Defensive patterns
Strategy: validation
Validate before calling
// Validate Uri authority before loading.
Uri uri = ...;
if (uri == null || TextUtils.isEmpty(uri.getAuthority())
|| !"android.resource".equals(uri.getScheme())) {
// reject or build a valid Uri
uri = Uri.parse("android.resource://" + ctx.getPackageName() + "/" + resId);
}
Glide.with(ctx).load(uri).into(img); Prevention
- Always include the package in the authority when building android.resource Uris.
- Prefer Glide.with(ctx).load(resId) over hand-built Uris.
- Validate scheme and authority before loading.
When it happens
Trigger: Constructing a Uri with scheme android.resource but a null/empty authority, e.g. Uri.parse("android.resource://"), or building a Uri via Uri.Builder() without calling .authority().
Common situations: Programmatically building a resource Uri and forgetting the package. Passing a malformed string to Uri.parse(). Stripping the authority during Uri manipulation.
Related errors
- Unrecognized Uri format: {source}
- Failed to find resource id for: {source}
- Failed to obtain context or unrecognized Uri format for: {so
- Loop count must be greater than 0, or equal to GlideDrawable
- Cannot apply transformation on width: {outWidth} or height:
AI-assisted analysis of bumptech/glide@eb14a895d8 (2026-08-14).
Data as JSON: /api/errors/e5f14a24604100db.
Report an issue: GitHub.