You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Resources$NotFoundException求助:Nexus 5X Oreo 8.1中Drawable资源缺失

资源找不到异常的修复方案与复现方法

错误日志

Caused by android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f08012e
   at android.content.res.ResourcesImpl.getResourceName(ResourcesImpl.java:253)
   at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:760)
   at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:630)
   at android.content.res.Resources.loadDrawable(Resources.java:886)
   at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:953)
   at android.content.res.TypedArray.getDrawable(TypedArray.java:928)

问题场景

该异常仅出现在**Nexus 5X(Oreo 8.1)**设备上,XML中ImageView引用的PNG图标已存在于drawable-hdpi、drawable-mdpi、drawable-xhdpi、drawable-xxhdpi、drawable-xxxhdpi文件夹,图标为小型PNG,无大小问题;项目最低SDK版本为API 21,模拟器测试未出现崩溃。

修复方案

  • 添加drawable-nodpi文件夹:在res目录下创建drawable-nodpi文件夹,将该PNG图标放入其中。Oreo 8.1的资源加载逻辑在高密度设备上可能存在密度匹配异常,nodpi资源会被系统直接使用,跳过密度适配逻辑,避免找不到对应密度资源的问题。
  • 排查资源ID冲突:执行命令aapt dump resources --values your-app.apk(替换your-app.apk为你的APK路径),查看资源ID#0x7f08012e对应的实际资源,确认是否存在ID重复导致的资源混淆。
  • 清理重建项目:执行./gradlew clean清理缓存,再执行./gradlew assembleDebug重新编译打包,避免旧缓存的资源ID或损坏的资源文件引发问题。
  • 检查XML引用正确性:确认ImageView的android:src或android:background属性引用的资源名称完全正确,无拼写错误、大小写错误(资源存在但引用错误也会触发找不到异常)。

复现方法

  • 使用**真实Nexus 5X设备(系统版本Oreo 8.1)**安装发布版APK(Debug版和模拟器的资源打包/加载逻辑与发布版存在差异,更易复现真实场景问题)。
  • 开启开发者选项中的不保留活动,多次打开、关闭包含目标ImageView的页面,强制系统反复加载资源,提升崩溃触发概率。
  • 通过adb logcat命令实时监控设备日志,当出现Resources$NotFoundException报错时,即可确认复现问题。

内容的提问来源于stack exchange,提问作者Ishu Sharma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 11:50:30