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

关于Resources$NotFoundException: Resource ID #0x20c0006崩溃的技术咨询

关于android.content.res.Resources$NotFoundException: Resource ID #0x20c0006崩溃的分析与修复

问题背景

自2024年1月24日起,线上用户反馈出现android.content.res.Resources$NotFoundException: Resource ID #0x20c0006崩溃,问题覆盖所有应用版本,约60%的崩溃发生在后台场景。核心疑问:

  • 该崩溃是否由Chrome更新引发?
  • 应如何修复?

崩溃堆栈信息

Caused by android.content.res.Resources$NotFoundException: Resource ID #0x20c0006
   at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:255)
   at android.content.res.MiuiResourcesImpl.getValue(MiuiResourcesImpl.java:96)
   at android.content.res.Resources.getInteger(Resources.java:1243)
   at org.chromium.ui.base.DeviceFormFactor.isTablet(chromium-TrichromeWebViewGoogle6432.aab-stable-616716433:9)
   at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
   at android.os.MessageQueue.next(MessageQueue.java:340)
   at android.os.Looper.loopOnce(Looper.java:169)
   at android.os.Looper.loop(Looper.java:300)
   at android.app.ActivityThread.main(ActivityThread.java:8301)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:577)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)

问题分析

崩溃是否由Chrome更新引发?

从堆栈可见,崩溃触发点在Chromium的DeviceFormFactor.isTablet方法中,该方法尝试获取系统资源config_smallestScreenWidthDp(对应ID 0x20c0006)失败。

Chrome/WebView的更新可能会触发进程重启或资源加载逻辑调整,使得原本隐藏的后台进程资源上下文被回收的问题暴露,但本质并非Chrome更新直接导致崩溃,而是更新后触发了资源失效的场景。核心原因是WebView相关进程在后台时,系统回收了其资源上下文,导致调用Resources.getInteger时找不到对应资源。

修复方案

  • 捕获异常并降级处理:在调用Chromium的isTablet方法时捕获Resources$NotFoundException, fallback到自定义的平板判断逻辑,避免崩溃。示例代码:
    public static boolean isTablet(Context context) {
        try {
            return org.chromium.ui.base.DeviceFormFactor.isTablet(context);
        } catch (Resources.NotFoundException e) {
            // 手动计算最小宽度dp,判断是否为平板
            DisplayMetrics metrics = context.getResources().getDisplayMetrics();
            float smallestWidthDp = Math.min(metrics.widthPixels / metrics.density, metrics.heightPixels / metrics.density);
            return smallestWidthDp >= 600; // 行业标准平板最小宽度阈值
        }
    }
    
  • 规避后台触发WebView相关逻辑:针对60%的后台崩溃场景,检查应用后台任务,尽量避免在后台进程中调用WebView或Chromium相关的设备判断、UI操作逻辑。若必须调用,提前验证上下文有效性或切换到前台执行。
  • 临时锁定WebView版本:若确认是特定Chrome/WebView版本触发问题,可临时锁定应用使用的WebView版本,但仅作为过渡方案,优先采用前两种方案从根源解决。

内容的提问来源于stack exchange,提问作者wenjie ma

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 12:42:45