android runtime_error ai_generated true

android.content.res.Resources$NotFoundException: Resource ID #0x7f0a000b type #0x12 is not valid

ID: android/resource-not-found-in-package

Also available as: JSON · Markdown · 中文
90%Fix Rate
85%Confidence
1Evidence
2023-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Android 5.0 - 14 active
AndroidX 1.0 - 1.7 active

Root Cause

A resource ID is referenced at runtime but the resource has been removed, renamed, or is in a different configuration (e.g., layout-land vs layout-port) that is not present in the current APK.

generic

中文

运行时引用了某个资源 ID,但该资源已被删除、重命名,或位于当前 APK 中不存在的配置中(例如 layout-land vs layout-port)。

Official Documentation

https://developer.android.com/reference/android/content/res/Resources.NotFoundException

Workarounds

  1. 85% success Check the resource ID by decoding it using 'adb shell dumpsys package <package> | grep resource' and ensure the resource exists in the APK by inspecting the R.txt file in the build/outputs folder.
    Check the resource ID by decoding it using 'adb shell dumpsys package <package> | grep resource' and ensure the resource exists in the APK by inspecting the R.txt file in the build/outputs folder.
  2. 95% success Add missing resource to all required configuration folders (e.g., drawable, drawable-land, drawable-night) or use a programmatic fallback: 'if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getDrawable(R.drawable.my_drawable, theme) } else { getResources().getDrawable(R.drawable.my_drawable) }'
    Add missing resource to all required configuration folders (e.g., drawable, drawable-land, drawable-night) or use a programmatic fallback: 'if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getDrawable(R.drawable.my_drawable, theme) } else { getResources().getDrawable(R.drawable.my_drawable) }'

中文步骤

  1. Check the resource ID by decoding it using 'adb shell dumpsys package <package> | grep resource' and ensure the resource exists in the APK by inspecting the R.txt file in the build/outputs folder.
  2. Add missing resource to all required configuration folders (e.g., drawable, drawable-land, drawable-night) or use a programmatic fallback: 'if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getDrawable(R.drawable.my_drawable, theme) } else { getResources().getDrawable(R.drawable.my_drawable) }'

Dead Ends

Common approaches that don't work:

  1. 50% fail

    If the resource is missing from the APK due to a build configuration issue (e.g., missing drawable variant), a rebuild alone won't fix it.

  2. 50% fail

    If the device uses a specific configuration (e.g., landscape), the resource might still be missing; the resource must be present in all relevant qualifier folders or use a fallback.