部分用户App启动崩溃:Resources$NotFoundException异常排查求助
解决Android启动页因缺失系统关联Drawable导致的随机崩溃
问题现象
Google Play后台监测到部分用户出现随机崩溃,崩溃栈如下:
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{views.activities.SplashActivity}: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class androidx.constraintlayout.widget.ConstraintLayout at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused by android.content.res.Resources$NotFoundException: Drawable (missing name) with resource ID #0x7f080141
经分析APK,资源ID 0x7f080141 对应 notification_template_icon_bg(ARGB值0x3333b5e5),但该Drawable资源不存在且未在代码中直接使用。
排查与解决方案
1. 修复资源压缩误删问题
若开启了R8/ProGuard资源压缩,可能误删了系统依赖的隐性资源:
- 在
res/raw/keep.xml中添加保留规则:<resources xmlns:tools="http://schemas.android.com/tools" tools:keep="@drawable/notification_template_icon_bg" /> - 或在
build.gradle的release配置中调整资源压缩策略:android { buildTypes { release { shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' // 避免过度裁剪系统关联资源 resConfigs "en", "zh-rCN" } } }
2. 手动添加缺失的Drawable资源
部分低版本Android系统会依赖应用内的同名系统Drawable备份,手动创建该资源:
在res/drawable目录下新建notification_template_icon_bg.xml,内容如下:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#3333b5e5" /> </shape>
3. 排查布局的隐性引用
检查SplashActivity对应XML布局的第17行附近,确认是否间接引用了依赖该Drawable的系统主题或自定义样式。比如某些继承系统通知样式的自定义View、主题属性,可能隐性引入了该资源,需调整相关样式配置。
4. 排查第三方库依赖
若集成了推送、通知类第三方库,可能其内部隐性依赖该Drawable:
- 升级第三方库到最新稳定版本
- 查看库的官方文档,确认是否需要额外配置资源
内容的提问来源于stack exchange,提问作者sanjana
相关产品推荐
相关产品推荐

