Android 10设备上的资源$NotFoundException

问题描述 投票:0回答:1

问题

我已经注意到很多意外的崩溃,只有在Android 10设备上。Crashes are pointing to missing resource ID in different layouts but I was not able to reproduce it even on same device and OS as I saw in crash reports.Weirdly enough, after hours of digging through google search results page 4 and further(I've got lost and results were in Mandarin) I found post pointing to Developer options -> Enable view attribute inspection. 在我的设备上启用它后,我已经可以重现它,但它仍然不清楚如何解决它。禁用它帮助和应用程序用户没有看到崩溃那里。

疑问

虽然帮了大忙,但我还是想知道是什么罪魁祸首,有什么正确的方法可以解决。

崩溃日志

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)

布局

<?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>

属性风格

<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相关的东西,因为那是布局中崩溃的指向。

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

设置

我使用属性,因为stylletheme是在独立的模块中定义的,并且使用材料库1.1。它发生在有proguard的prod应用版本上。

android android-theme android-10.0
1个回答
0
投票

好吧,经过一些更多的调查与混淆的构建发现,问题是丢失的自定义属性本身。

在下面的Assetmanager查找过程中,它无法找到自定义样式属性。

@UnsupportedAppUsage @Nullable String getResourceEntryName(@AnyRes int resId) { synchronized (this) { ensureValidLocked(); return nativeGetResourceEntryName(mObject, resId); } }

它找不到自定义样式属性。只有当开发选项 "查看属性检查 "在混淆构建中被启用时才会发生。

更新dexguard规则,如下图所示,解决了这个问题。

-keepresources attr/**
© www.soinside.com 2019 - 2024. All rights reserved.