android
runtime_error
ai_generated
true
android.content.res.Resources$NotFoundException: 资源 ID #0x7f0a000b 类型 #0x12 无效
android.content.res.Resources$NotFoundException: Resource ID #0x7f0a000b type #0x12 is not valid
ID: android/resource-not-found-in-package
90%修复率
85%置信度
1证据数
2023-01-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Android 5.0 - 14 | active | — | — | — |
| AndroidX 1.0 - 1.7 | active | — | — | — |
根因分析
运行时引用了某个资源 ID,但该资源已被删除、重命名,或位于当前 APK 中不存在的配置中(例如 layout-land vs layout-port)。
English
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.
官方文档
https://developer.android.com/reference/android/content/res/Resources.NotFoundException解决方案
-
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.
-
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) }'
无效尝试
常见但无效的做法:
-
50% 失败
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.
-
50% 失败
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.