社区首页 >问答首页 >Android 10设备上的资源$NotFoundException

Android 10设备上的资源$NotFoundException
EN

Stack Overflow用户
提问于 2020-06-03 23:17:47
回答 1查看 640关注 0票数 0

问题

我注意到很多意外的崩溃只是在Android 10设备上。崩溃正指向不同布局中缺少的资源ID,但我无法在与在崩溃reports.Weirdly中看到的相同的设备和操作系统上复制它,在搜索谷歌搜索结果第4页和更远的几个小时(我迷路了,结果是普通话)之后,我找到了指向开发人员选项的帖子-> Enable视图属性检查。在我的设备上启用它之后,我可以复制它,但它仍然不清楚如何修复它。禁用它起了作用,应用程序用户也没有看到那里的崩溃。

问题

尽管这帮了我的忙,但我想知道它的罪魁祸首是什么,以及修复它的正确方法是什么。

崩溃日志

代码语言:javascript
代码运行次数:0
复制
android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f040378
    at android.content.res.ResourcesImpl.getResourceTypeName(ResourcesImpl.java:305)
    at android.content.res.Resources.getResourceTypeName(Resources.java:2111)
    at android.content.res.Resources$Theme.getExplicitStyle(Resources.java:1769)
    at android.view.View.retrieveExplicitStyle(View.java:6731)
    at android.view.View.<init>(View.java:5639)
    at android.view.ViewGroup.<init>(ViewGroup.java:687)
    at android.widget.FrameLayout.<init>(FrameLayout.java:99)
    at android.widget.FrameLayout.<init>(FrameLayout.java:94)
    at androidx.cardview.widget.CardView.<init>(SourceFile:121)
    at com.google.android.material.card.MaterialCardView.<init>(SourceFile:52)
    at com.google.android.material.card.MaterialCardView.<init>(SourceFile:48)
    at java.lang.reflect.Constructor.newInstance0(Constructor.java)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
    at android.view.LayoutInflater.createView(LayoutInflater.java:854)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
    at androidx.databinding.DataBindingUtil.inflate$45cd3863(SourceFile:126)
    at androidx.databinding.ViewDataBinding.inflateInternal$5250870e(SourceFile:1366)
    at com.example.app.LoginFragmentBinding.inflate(SourceFile:1090)
    at com.example.app.LoginFragment.onCreateView(SourceFile:66)
    at androidx.fragment.app.Fragment.performCreateView(SourceFile:2439)
    at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(SourceFile:1460)
    at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(SourceFile:1784)
    at androidx.fragment.app.BackStackRecord.executeOps(SourceFile:797)
    at androidx.fragment.app.FragmentManagerImpl.executeOps(SourceFile:2625)
    at androidx.fragment.app.FragmentManagerImpl.moveToState(SourceFile:2411)
    at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(SourceFile:2366)
    at androidx.fragment.app.FragmentManagerImpl.execPendingActions(SourceFile:2273)
    at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(SourceFile:3273)
    at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(SourceFile:3229)
    at androidx.fragment.app.Fragment.performActivityCreated(SourceFile:2466)
    at androidx.fragment.app.FragmentManagerImpl.moveToState(SourceFile:1483)
    at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(SourceFile:1784)
    at androidx.fragment.app.BackStackRecord.executeOps(SourceFile:797)
    at androidx.fragment.app.FragmentManagerImpl.executeOps(SourceFile:2625)
    at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(SourceFile:2411)
    at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(SourceFile:2366)
    at androidx.fragment.app.FragmentManagerImpl.execPendingActions(SourceFile:2273)
    at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(SourceFile:3273)
    at androidx.fragment.app.FragmentActivity.androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(SourceFile:17229)
    at androidx.appcompat.app.AppCompatActivity.onStart(SourceFile:178)
    at com.ing.mobile.app.activities.INGMobileActivity.onStart(SourceFile:145)
    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1433)
    at android.app.Activity.performStart(Activity.java:7978)
    at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3472)
    at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
    at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:7814)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

布局

代码语言:javascript
代码运行次数:0
复制
<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>

        <import type="model.CustomerType" />

        <import type="android.view.View" />

        <import type="AccessibilityUtils" />

        <variable
            name="view"
            type="login.LoginView" />

        <variable
            name="presenter"
            type="login.LoginPresenter" />
    </data>

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:liftOnScroll="?attr/myAppBarLayoutScrollingBehaviorEnabled">
            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?android:attr/actionBarSize"
                app:navigationContentDescription="@string/login__cancel_content_description"
                app:navigationIcon="?attr/navigationCloseDrawable">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:contentDescription="@string/login__header_content_description"
                    app:srcCompat="@drawable/logo" />
            </androidx.appcompat.widget.Toolbar>
        </com.google.android.material.appbar.AppBarLayout>

        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="?attr/myAppBarLayoutScrollingBehavior">

            <com.google.android.material.card.MaterialCardView
                style="?attr/myCardViewFullWidthStyle"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                app:contentPadding="0dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <com.google.android.material.tabs.TabLayout
                        android:id="@+id/tabs"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:tabGravity="fill"
                        app:tabMode="fixed" />

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:padding="@dimen/card_content_padding">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:focusable="true"
                            android:orientation="vertical"
                            android:visibility="@{view.customerType == CustomerType.PRIVATE ? View.VISIBLE : View.GONE}">

                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginBottom="@dimen/text_vertical_spacing"
                                android:text="@string/login__title_private"
                                android:textAppearance="?attr/textAppearanceHeadline5" />

                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:contentDescription="@string/login__body_private_accessibility"
                                android:text="@{AccessibilityUtils.makeWordAccessible(@string/login__body_private)}" />

                        </LinearLayout>

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:focusable="true"
                            android:orientation="vertical"
                            android:visibility="@{view.customerType == CustomerType.BUSINESS ? View.VISIBLE : View.GONE}">

                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginBottom="@dimen/text_vertical_spacing"
                                android:text="@string/login__title_business"
                                android:textAppearance="?attr/textAppearanceHeadline5" />

                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:contentDescription="@string/login__body__accessibility"
                                android:text="@{AccessibilityUtils.makeWordAccessible(@string/login__body)}" />

                        </LinearLayout>

                        <com.google.android.material.textfield.TextInputLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="-4dp"
                            android:layout_marginTop="16dp"
                            android:layout_marginEnd="-4dp"
                            android:layout_marginBottom="@dimen/input_vertical_spacing"
                            android:hint="@string/login__username">

                            <com.google.android.material.textfield.TextInputEditText
                                android:id="@+id/username"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:singleLine="true"
                                android:text="@={view.username}" />

                        </com.google.android.material.textfield.TextInputLayout>

                        <com.google.android.material.textfield.TextInputLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="-4dp"
                            android:layout_marginEnd="-4dp"
                            android:hint="@string/login_password_hint">

                            <com.google.android.material.textfield.TextInputEditText
                                android:id="@+id/password"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:inputType="textPassword"
                                android:singleLine="true"
                                android:text="@={view.password}" />
                        </com.google.android.material.textfield.TextInputLayout>

                        <com.google.android.material.button.MaterialButton
                            android:id="@+id/login_button"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="@dimen/buttons_margin_top"
                            android:layout_marginBottom="@dimen/button_vertical_spacing"
                            android:onClick="@{() -> presenter.onLoginClicked(view.username, view.password)}"
                            android:text="@string/login_label" />

                        <com.google.android.material.button.MaterialButton
                            android:id="@+id/help_button"
                            style="?attr/buttonTextStyle"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:onClick="@{() -> presenter.onForgotCredentialsClicked()}"
                            android:text="@string/login_help" />
                    </LinearLayout>
                </LinearLayout>
            </com.google.android.material.card.MaterialCardView>
        </androidx.core.widget.NestedScrollView>
    </androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>

Attribute/Style

代码语言:javascript
代码运行次数:0
复制
<item name="myCardViewFullWidthStyle">@style/CardView.FullWidth</item>
    <style name="CardView.FullWidth" parent="Widget.MaterialComponents.CardView">
        <item name="cardCornerRadius">@dimen/card_fullwidth_corner_radius</item>
        <item name="cardElevation">@dimen/card_fullwidth_elevation</item>
        <item name="contentPadding">@dimen/card_fullwidth_content_padding</item>
        <item name="android:layout_width">@dimen/card_fullwidth_width</item>
        <item name="android:layout_marginTop">@dimen/card_fullwidth_margin_top</item>
        <item name="android:layout_marginBottom">@dimen/card_fullwidth_margin_bottom</item>
    </style>

而系统找不到的资源ID #0x7f040378似乎是style="?attr/myCardViewFullWidthStyle",或者至少是与CardView相关的东西,因为崩溃就是在布局中指向的。

代码语言:javascript
代码运行次数:0
复制
    <com.google.android.material.card.MaterialCardView
        style="?attr/myCardViewFullWidthStyle"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        app:contentPadding="0dp">

设置

Im使用属性,因为样式/主题是在分隔模块中定义的,并且使用material 1.1。这种情况发生在prod应用程序版本上。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-04 02:35:47

好的,在对模糊构建进行了进一步的调查之后,发现问题在于缺少的自定义属性本身。

在资产管理器的以下查找过程中:

代码语言:javascript
代码运行次数:0
复制
@UnsupportedAppUsage @Nullable String getResourceEntryName(@AnyRes int resId) { synchronized (this) { ensureValidLocked(); return nativeGetResourceEntryName(mObject, resId); } }

它找不到自定义样式属性。只有在模糊构建上启用了dev选项“查看属性检查”时,才会出现这种情况。

更新右旋保护规则,如下所示修复它

代码语言:javascript
代码运行次数:0
复制
-keepresources attr/**
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62188879

复制
相关文章
Android 设备上使用 Wi-Fi Settings
在 Android 设备上使用 Wi-Fi Settings 设置代理的详细教程:
华科云商小孙
2023/10/17
3560
android设备上如何运行C语言原生程序
前言 咱们知道android设备可以直接运行apk应用,或者使用dalvikvm指令运行dex文件中的程序, 但是这两者本质上使用的语言都是java或者smali, 如果需要执行C语言程序,需要借助N
乱码三千
2021/08/24
5.4K0
使用adb logcat命令显示Android设备上的Log日志
实现这个功能的前提是使用adb命令,所以必须要有手机和电脑,还有安装adb,adb程序是很小的几M就可以。
全栈程序员站长
2022/06/28
11.9K0
使用adb logcat命令显示Android设备上的Log日志
安卓热修篇-Shadow-思想篇
本人17年毕业于中山大学,于2018年7月加入37手游安卓团队,曾经就职于久邦数码担任安卓开发工程师;
37手游安卓团队
2020/11/12
1.3K0
OTT设备上SSAI的未来
本文是来自MHV (Mile High Video) 2019的演讲,作者是来自于Mux公司的Phil Cluff。本次演讲主要讲述了OTT设备上SSAI的应用情况及前景。
用户1324186
2019/10/23
1.1K0
《我的PaddlePaddle学习之路》笔记十四——把PaddlePaddle迁移到Android设备上
PaddlePaddle还可以迁移到Android或者Linux设备上,在这些部署了PaddlePaddle的设备同样可以做深度学习的预测。在这篇文章中我们就介绍如何把PaddlePaddle迁移到Android手机上,并在Android的APP中使用PaddlePaddle。
夜雨飘零
2020/05/06
2.7K0
《我的PaddlePaddle学习之路》笔记十四——把PaddlePaddle迁移到Android设备上
Android图片资源
用户1172465
2018/01/05
1.2K0
Android图片资源
货拉拉 Android 动态资源管理系统原理与实践(上)
该过程每个资源不同,sdk使用方无需修改内置资源的应用方式,对于自定义资源,需要使用方自行决定应用方式。
用户1907613
2022/12/12
1K0
货拉拉 Android 动态资源管理系统原理与实践(上)
Android小知识10则(上)(2018.8重编版)
Android小知识10则(下) 前言 Android的知识还是比较碎的, 日常积累很重要. 我把平常一些小知识点整合整合, 理成了上下两篇文章, 每篇五个知识点. ---- 横竖屏锁定 有两种方法可以实现 使用配置文件 在AndroidManifest.xml的activity标签下添加android:screenOrientation="portrait"即可.默认是android:screenOrientation="unspecified", 也就是根据系统当前的横竖屏状态切换.
sean_yang
2018/09/04
6080
Android小知识10则(上)(2018.8重编版)
【10】Hexo博客的跨设备同步
前几天使用hexo搭建了Github博客,今天在公司的电脑上想要同步Github博客到本地,遇到了点坑,查询了 一下网上的资料,现在记录一下,也算给遇到同样问题的小伙伴们一个参考。
代码咖啡
2018/08/28
7420
【10】Hexo博客的跨设备同步
Android根据资源名获取资源ID
接触过Android开发的同学们都知道在Android中访问程序资源基本都是通过资源ID来访问。这样开发起来很简单,并且可以不去考虑各种分辨率,语言等不同资源显式指定。
技术小黑屋
2018/09/04
3.5K0
android 获取设备信息
//手机号码 public static String getLine1Number(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (tm == null) { return ""; } return "" + tm.getLine1
再见孙悟空_
2023/02/10
1.5K0
Android 动态获取资源的ID
但是对于以上做法, 官方并不推荐,并且 getIdentifier这个写library的时候, 如果里面需要引用主程的资源且R所在的包名未知时还是很有用的(如果在gradle里修改了packageName, R所在的包名是和packageName不一样的,没法反射),当然也是有解决的办法: 如果愿意,是可以根据业务拼接出 “package_name.R.drawable.class” 的。但是如果这样的话,视具体情况一定有更好的解法。
胖虎哥
2023/05/10
2.5K0
android 资源文字ids的作用
ids.xml——为应用的相关资源提供唯一的资源id。id是为了获得xml中的对象而需要的参数,也就是Object = findViewById(R.id.id_name)中的id_name。这些值可以在代码中用android.R.id引用到。若在ids.xml中定... ids.xml——为应用的相关资源提供唯一的资源id。id是为了获得xml中的对象而需要的参数,也就是Object = findViewById(R.id.id_name)中的id_name。这些值可以在代码中用android.R.id引
xiangzhihong
2018/02/01
1.7K0
Android平台GB28181设备接入端如何降低资源占用和性能消耗
我们在做GB28181设备接入模块的时候,考虑到好多设备性能一般,我们一般的设计思路是,先注册设备到平台侧,平台侧发calalog过来,获取设备信息,然后,设备侧和国标平台侧维持心跳,如果有位置订阅信息,按照订阅时间间隔,实时上报设备位置信息。
音视频牛哥
2023/08/06
2640
Android平台GB28181设备接入端如何降低资源占用和性能消耗
偶遇 android.content.res.Resources$NotFoundException: BUG可让我一顿好找。特此记录!
2.inflate 文件的时候 R.Layout.****, 写成了R.id.***** 这种很显然不是。。。
对话、
2022/02/22
8510
偶遇 android.content.res.Resources$NotFoundException: BUG可让我一顿好找。特此记录!
Android之assets资源
assets目录下存放的原生资源文件,通过getAssets()方法获取. 使用: InputStream inputStream; try { inputStream = getAssets().open("data/chat.isp"); String json = StringUtil.readTextFile(inputStream); JSONArray array = new
欢醉
2018/01/22
6890
点击加载更多

相似问题

某些设备上的资源$NotFoundException (setIcon)

16

Android 4.4上的资源$NotFoundException

10

Android资源$NotFoundException

10

Android:资源$NotFoundException

21

Android:资源$NotFoundException

31
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文