bumptech/glide · error · IllegalArgumentException

Failed to obtain context or unrecognized Uri format for: {so

Error message

Failed to obtain context or unrecognized Uri format for: {source}

What it means

IllegalArgumentException thrown by ResourceDrawableDecoder.findContextForPackage() when context.createPackageContext(packageName) throws NameNotFoundException and the requested package is not a parent of the current app (i.e. not a split). Glide cannot obtain a Context to load resources from an uninstalled or unknown package.

Source

Thrown at library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java:108

    return NonOwnedDrawableResource.newInstance(drawable);
  }

  @NonNull
  private Context findContextForPackage(Uri source, @NonNull String packageName) {
    // Fast path
    if (packageName.equals(context.getPackageName())) {
      return context;
    }

    try {
      return context.createPackageContext(packageName, /* flags= */ 0);
    } catch (NameNotFoundException e) {
      // 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

View on GitHub (pinned to eb14a895d8)

Solutions

  1. Verify the target package is installed via PackageManager.getPackageInfo(name, 0) before loading.
  2. Use the current app's package name when loading your own resources.
  3. Provide an .error() drawable fallback for uninstalled packages.
  4. For dynamic feature modules, ensure the module is installed before requesting its resources.

Example fix

// before
Uri uri = Uri.parse("android.resource://com.other.app/drawable/icon");
Glide.with(ctx).load(uri).into(img);
// after
try {
  pm.getPackageInfo("com.other.app", 0);
  Glide.with(ctx).load(uri).into(img);
} catch (NameNotFoundException e) {
  img.setImageResource(R.drawable.default_icon);
}
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the package is installed before loading its resources.
try {
  ctx.getPackageManager().getPackageInfo(packageName, 0);
  // safe to load
} catch (PackageManager.NameNotFoundException e) {
  // fall back
}

Try / catch

try { Glide.with(ctx).load(uri).into(img); }
catch (IllegalArgumentException e) {
  if (e.getMessage() != null && e.getMessage().startsWith("Failed to obtain context")) {
    img.setImageResource(R.drawable.default_icon);
  } else throw e;
}

Prevention

When it happens

Trigger: Loading an android.resource:// Uri whose authority names a package that is not installed and is not the current app or a split of it.

Common situations: Loading another app's icon (e.g. com.android.camera2) when that app is not installed. Hardcoded package names that drift across OEM builds. Loading resources from an uninstalled dynamic feature module.

Related errors


AI-assisted analysis of bumptech/glide@eb14a895d8 (2026-08-14). Data as JSON: /api/errors/0b20a5cfd1bfe8b3. Report an issue: GitHub.