bumptech/glide · error · IllegalArgumentException
Unrecognized Uri format: {source}
Error message
Unrecognized Uri format: {source} What it means
IllegalArgumentException thrown by ResourceDrawableDecoder.findResourceIdFromUri() when the number of path segments is neither 2 (type/name form) nor 1 (resource-id form). Glide only supports two android.resource:// URI shapes; anything else is rejected.
Source
Thrown at library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java:121
// The parent APK holds the correct context if the resource is located in a split
if (packageName.contains(context.getPackageName())) {
return context;
}
throw new IllegalArgumentException(
"Failed to obtain context or unrecognized Uri format for: " + source, e);
}
}
@DrawableRes
private int findResourceIdFromUri(Context context, Uri source) {
List<String> segments = source.getPathSegments();
if (segments.size() == NAME_URI_PATH_SEGMENTS) {
return findResourceIdFromTypeAndNameResourceUri(context, source);
} else if (segments.size() == ID_PATH_SEGMENTS) {
return findResourceIdFromResourceIdUri(source);
} else {
throw new IllegalArgumentException("Unrecognized Uri format: " + source);
}
}
// android.resource://com.android.camera2/mipmap/logo_camera_color
@DrawableRes
private int findResourceIdFromTypeAndNameResourceUri(Context context, Uri source) {
List<String> segments = source.getPathSegments();
String packageName = source.getAuthority();
String typeName = segments.get(TYPE_PATH_SEGMENT_INDEX);
String resourceName = segments.get(NAME_PATH_SEGMENT_INDEX);
int result = context.getResources().getIdentifier(resourceName, typeName, packageName);
if (result == MISSING_RESOURCE_ID) {
result = Resources.getSystem().getIdentifier(resourceName, typeName, ANDROID_PACKAGE_NAME);
}
if (result == MISSING_RESOURCE_ID) {
throw new IllegalArgumentException("Failed to find resource id for: " + source);
}
return result;View on GitHub (pinned to eb14a895d8)
Solutions
- Use one of the two supported forms: android.resource://<package>/<type>/<name> or android.resource://<package>/<resId>.
- Prefer Glide.with(ctx).load(resId) for your own resources.
- Inspect source.getPathSegments().size() before handing the Uri to Glide.
Example fix
// before
Uri uri = Uri.parse("android.resource://com.example/"); // 0 segments
// after
Uri uri = Uri.parse("android.resource://com.example/drawable/icon"); Defensive patterns
Strategy: validation
Validate before calling
// Validate path-segment count before loading.
List<String> segs = uri.getPathSegments();
boolean ok = "android.resource".equals(uri.getScheme())
&& !TextUtils.isEmpty(uri.getAuthority())
&& (segs.size() == 2 || segs.size() == 1);
if (!ok) { /* rebuild or fall back */ } Prevention
- Stick to the two supported android.resource URI forms.
- Prefer .load(resId) for your own resources.
- Validate segment count before loading.
When it happens
Trigger: Passing an android.resource:// URI with 0 or 3+ path segments, e.g. android.resource://com.example/ (zero segments) or android.resource://com.example/a/b/c.
Common situations: Manually constructing resource Uris and adding extra path components. Uri.parse on a string with trailing slashes creating empty segments. Confusing resource Uris with content: Uris.
Related errors
- Package name for {source} is null or empty
- 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/de1cebcddabcd2c4.
Report an issue: GitHub.