Mr.AndroidShin / Dev Tools

Debugging log · Resources

Resources$NotFoundException at runtime

The app compiled clean and ran fine on my phone, then crashed on a user's device with android.content.res.Resources$NotFoundException and a bare numeric resource id like 0x7f08007a. The resource obviously existed — the build referenced it by a real R name. The confusing part is that a resource can be referenceable at compile time and still be unresolvable at runtime on a particular device, and the id in the message is no help until you translate it back.

The short version: the resource id was valid at build but couldn't be loaded on that device at that moment. Usual causes: resource shrinking removed it, a vector/attribute isn't supported on the device's API level, or the right configuration variant (density, locale, night mode) is missing. Translate the hex id to a name first, then match it to one of these.

The error

android.content.res.Resources$NotFoundException:
  Resource ID #0x7f08007a

That hex is a packed resource id, not something you can read directly. Find it in R.txt (in your build outputs) or with the APK Analyzer to see which resource name it maps to. Knowing the actual resource — a drawable, a string, a layout — tells you which of the causes below applies.

Cause 1 — resource shrinking removed it

If you have shrinkResources on for release, the build strips resources it thinks are unused. When a resource is referenced only indirectly — by name through getIdentifier(), or from reflection, or a library loads it dynamically — the shrinker can't see the reference and removes it. The app then crashes when it finally asks for it at runtime. This is the classic "works in debug, crashes in release" version of this error.

The fix is to tell the shrinker to keep it, via a keep.xml:

<!-- res/raw/keep.xml -->
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:keep="@drawable/dynamically_used_*,@string/looked_up_by_name" />

Prefer referencing resources statically where you can, so the shrinker sees them; use keep.xml for the genuinely dynamic ones. This is the resource-level cousin of R8 keep rules for code.

Cause 2 — the resource isn't supported on that API level

Some resources only resolve on new enough APIs. A vector drawable used directly as a background, a drawable that uses an attribute introduced in a later platform version, or a theme attribute the device doesn't know — these can crash on older devices while working on your newer test phone. The fix depends on the specific resource: enable the compat path for vectors (and reference them in ways the support library can inflate), or provide an API-specific alternative under a versioned resource folder (e.g. a drawable-v24 variant) so old devices get something they can load.

Cause 3 — a missing configuration variant

Resources resolve per-configuration: density, locale, orientation, night mode. If a resource exists for some configurations but not the one the device is in, the lookup can fail. Common shapes: a drawable present only in one density bucket, a string missing from the default (unqualified) values so a device in an unlisted locale finds nothing, or a -night resource with no day-mode fallback. Make sure every resource has a sensible default variant (the unqualified folder) so there's always something to fall back to.

The debugging order that saves time: translate the hex id to a name, then ask "is this release-only?" If yes, suspect resource shrinking first. If it's device-specific, suspect API level or a missing configuration variant. Chasing the fix before you know the resource name is how this one eats an afternoon.

Checklist

Resource ids and names above are examples — use the ones from your own crash and R.txt.