{"record":{"id":"0b20a5cfd1bfe8b3","repo":"bumptech/glide","slug":"failed-to-obtain-context-or-unrecognized-uri-forma","errorCode":null,"errorMessage":"Failed to obtain context or unrecognized Uri format for: {source}","messagePattern":"Failed to obtain context or unrecognized Uri format for: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java","lineNumber":108,"sourceCode":"    return NonOwnedDrawableResource.newInstance(drawable);\n  }\n\n  @NonNull\n  private Context findContextForPackage(Uri source, @NonNull String packageName) {\n    // Fast path\n    if (packageName.equals(context.getPackageName())) {\n      return context;\n    }\n\n    try {\n      return context.createPackageContext(packageName, /* flags= */ 0);\n    } catch (NameNotFoundException e) {\n      // The parent APK holds the correct context if the resource is located in a split\n      if (packageName.contains(context.getPackageName())) {\n        return context;\n      }\n\n      throw new IllegalArgumentException(\n          \"Failed to obtain context or unrecognized Uri format for: \" + source, e);\n    }\n  }\n\n  @DrawableRes\n  private int findResourceIdFromUri(Context context, Uri source) {\n    List<String> segments = source.getPathSegments();\n    if (segments.size() == NAME_URI_PATH_SEGMENTS) {\n      return findResourceIdFromTypeAndNameResourceUri(context, source);\n    } else if (segments.size() == ID_PATH_SEGMENTS) {\n      return findResourceIdFromResourceIdUri(source);\n    } else {\n      throw new IllegalArgumentException(\"Unrecognized Uri format: \" + source);\n    }\n  }\n\n  // android.resource://com.android.camera2/mipmap/logo_camera_color\n  @DrawableRes","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java#L90-L126","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the target package is installed via PackageManager.getPackageInfo(name, 0) before loading.","Use the current app's package name when loading your own resources.","Provide an .error() drawable fallback for uninstalled packages.","For dynamic feature modules, ensure the module is installed before requesting its resources."],"exampleFix":"// before\nUri uri = Uri.parse(\"android.resource://com.other.app/drawable/icon\");\nGlide.with(ctx).load(uri).into(img);\n// after\ntry {\n  pm.getPackageInfo(\"com.other.app\", 0);\n  Glide.with(ctx).load(uri).into(img);\n} catch (NameNotFoundException e) {\n  img.setImageResource(R.drawable.default_icon);\n}","handlingStrategy":"validation","validationCode":"// Confirm the package is installed before loading its resources.\ntry {\n  ctx.getPackageManager().getPackageInfo(packageName, 0);\n  // safe to load\n} catch (PackageManager.NameNotFoundException e) {\n  // fall back\n}","typeGuard":null,"tryCatchPattern":"try { Glide.with(ctx).load(uri).into(img); }\ncatch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Failed to obtain context\")) {\n    img.setImageResource(R.drawable.default_icon);\n  } else throw e;\n}","preventionTips":["Check package installation via PackageManager before loading cross-package resources.","Use .error() for uninstalled package icons.","Ensure dynamic feature modules are installed before loading their resources."],"tags":["uri","drawable","package","context","android"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}