问题
我注意到很多意外的崩溃只是在Android 10设备上。崩溃正指向不同布局中缺少的资源ID,但我无法在与在崩溃reports.Weirdly中看到的相同的设备和操作系统上复制它,在搜索谷歌搜索结果第4页和更远的几个小时(我迷路了,结果是普通话)之后,我找到了指向开发人员选项的帖子-> Enable视图属性检查。在我的设备上启用它之后,我可以复制它,但它仍然不清楚如何修复它。禁用它起了作用,应用程序用户也没有看到那里的崩溃。
问题
尽管这帮了我的忙,但我想知道它的罪魁祸首是什么,以及修复它的正确方法是什么。
崩溃日志
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>
Attribute/Style
<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">
设置
Im使用属性,因为样式/主题是在分隔模块中定义的,并且使用material 1.1。这种情况发生在prod应用程序版本上。
发布于 2020-06-04 02:35:47
好的,在对模糊构建进行了进一步的调查之后,发现问题在于缺少的自定义属性本身。
在资产管理器的以下查找过程中:
@UnsupportedAppUsage @Nullable String getResourceEntryName(@AnyRes int resId) { synchronized (this) { ensureValidLocked(); return nativeGetResourceEntryName(mObject, resId); } }
它找不到自定义样式属性。只有在模糊构建上启用了dev选项“查看属性检查”时,才会出现这种情况。
更新右旋保护规则,如下所示修复它
-keepresources attr/**
https://stackoverflow.com/questions/62188879
复制相似问题