非法状态异常:无法加载字体(Jetpack合成)在三星Galaxy S22 Ultra + Android 13上

wbrvyc0a  于 2022-11-27  发布在  Android
关注(0)|答案(1)|浏览(195)

我们已经注意到了很多“无法加载字体”-崩溃,具体在三星Galaxy S22 Ultra与Android 13.到目前为止,我们还不能再现它自己.我已经在谷歌上搜索了很多,但没有找到这样的.
下面是我们在Jetpack Compose中使用字体的方式:
第一个
这是堆栈跟踪:

Fatal Exception: java.lang.IllegalStateException: Could not load font
       at androidx.compose.ui.text.font.TypefaceRequestCache.runCached(FontFamilyResolver.kt:205)
       at androidx.compose.ui.text.font.FontFamilyResolverImpl.resolve(FontFamilyResolver.kt:94)
       at androidx.compose.ui.text.font.FontFamilyResolverImpl.resolve-DPcqOEQ(FontFamilyResolver.kt:81)
       at androidx.compose.ui.text.platform.AndroidParagraphIntrinsics$resolveTypeface$1.invoke-DPcqOEQ(AndroidParagraphIntrinsics.android.kt:79)
       at androidx.compose.ui.text.platform.AndroidParagraphIntrinsics$resolveTypeface$1.invoke(AndroidParagraphIntrinsics.android.kt:77)
       at androidx.compose.ui.text.platform.extensions.TextPaintExtensions_androidKt.applySpanStyle(TextPaintExtensions.android.kt:54)
       at androidx.compose.ui.text.platform.AndroidParagraphIntrinsics.<init>(AndroidParagraphIntrinsics.android.kt:90)
       at androidx.compose.ui.text.platform.AndroidParagraphIntrinsics_androidKt.ActualParagraphIntrinsics(AndroidParagraphIntrinsics.android.kt:154)
       at androidx.compose.ui.text.ParagraphIntrinsicsKt.ParagraphIntrinsics(ParagraphIntrinsics.kt:98)
       at androidx.compose.ui.text.MultiParagraphIntrinsics.<init>(MultiParagraphIntrinsics.kt:102)
       at androidx.compose.foundation.text.TextDelegate.layoutIntrinsics(TextDelegate.kt:130)
       at androidx.compose.foundation.text.TextDelegate.layoutText-K40F9xA(TextDelegate.kt:154)
       at androidx.compose.foundation.text.TextDelegate.layout-NN6Ew-U(TextDelegate.kt:241)
       at androidx.compose.foundation.text.TextController$measurePolicy$1.measure-3p2s80s(CoreText.kt:309)
       at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:44)
       at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:405)
       at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:53)
       at androidx.compose.foundation.layout.PaddingModifier.measure-3p2s80s(Padding.kt:364)
       at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:53)
       at androidx.compose.ui.node.LayoutNode$performMeasure$1.invoke(LayoutNode.kt:1388)
       at androidx.compose.ui.node.LayoutNode$performMeasure$1.invoke(LayoutNode.kt:1387)
       at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:2063)
       at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:112)
       at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:78)
       at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:66)
       at androidx.compose.ui.node.LayoutNode.performMeasure-BRTryo0$ui_release(LayoutNode.kt:1387)
       at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
       at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:75)
       at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1331)
       at androidx.compose.foundation.lazy.layout.LazyLayoutMeasureScopeImpl.measure-0kLqBqw(LazyLayoutMeasureScope.kt:120)
       at androidx.compose.foundation.lazy.LazyMeasuredItemProvider.getAndMeasure-ZjPyQlc(LazyMeasuredItemProvider.kt:47)
       at androidx.compose.foundation.lazy.LazyListMeasureKt.measureLazyList-7Xnphek(LazyListMeasure.kt:149)
       at androidx.compose.foundation.lazy.LazyListKt$rememberLazyListMeasurePolicy$1$1.invoke-0kLqBqw(LazyList.kt:267)
       at androidx.compose.foundation.lazy.LazyListKt$rememberLazyListMeasurePolicy$1$1.invoke(LazyList.kt:195)
       at androidx.compose.foundation.lazy.layout.LazyLayoutKt$LazyLayout$2$1.invoke-0kLqBqw(LazyLayout.kt:74)
       at androidx.compose.foundation.lazy.layout.LazyLayoutKt$LazyLayout$2$1.invoke(LazyLayout.kt:70)
       at androidx.compose.ui.layout.LayoutNodeSubcompositionsState$createMeasurePolicy$1.measure-3p2s80s(SubcomposeLayout.kt:581)
       at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:44)
       at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:405)
       at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:53)
       at androidx.compose.foundation.layout.FillModifier.measure-3p2s80s(Size.kt:658)
       at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:53)
       at androidx.compose.ui.node.LayoutNode$performMeasure$1.invoke(LayoutNode.kt:1388)
       at androidx.compose.ui.node.LayoutNode$performMeasure$1.invoke(LayoutNode.kt:1387)
       at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:2063)
       at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:112)
       at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:78)
       at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:66)
       at androidx.compose.ui.node.LayoutNode.performMeasure-BRTryo0$ui_release(LayoutNode.kt:1387)
       at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
       at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:75)
       at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1331)
       at androidx.constraintlayout.compose.Measurer.measure(ConstraintLayout.kt:1864)
       at androidx.constraintlayout.core.widgets.ConstraintWidgetContainer.measure(ConstraintWidgetContainer.java:632)
       at androidx.constraintlayout.core.widgets.analyzer.Direct.verticalSolvingPass(Direct.java:453)
       at androidx.constraintlayout.core.widgets.analyzer.Direct.solveVerticalMatchConstraint(Direct.java:750)
       at androidx.constraintlayout.core.widgets.analyzer.Direct.verticalSolvingPass(Direct.java:505)
       at androidx.constraintlayout.core.widgets.analyzer.Direct.verticalSolvingPass(Direct.java:544)
       at androidx.constraintlayout.core.widgets.analyzer.Direct.solvingPass(Direct.java:224)
       at androidx.constraintlayout.core.widgets.ConstraintWidgetContainer.layout(ConstraintWidgetContainer.java:693)
       at androidx.constraintlayout.core.widgets.analyzer.BasicMeasure.solveLinearSystem(BasicMeasure.java:160)
       at androidx.constraintlayout.core.widgets.analyzer.BasicMeasure.solverMeasure(BasicMeasure.java:291)
       at androidx.constraintlayout.core.widgets.ConstraintWidgetContainer.measure(ConstraintWidgetContainer.java:120)
       at androidx.constraintlayout.compose.Measurer.performMeasure-DjhGOtQ(ConstraintLayout.kt:2095)
       at androidx.constraintlayout.compose.ConstraintLayoutKt$rememberConstraintLayoutMeasurePolicy$1$measurePolicy$1.measure-3p2s80s(ConstraintLayout.kt:122)
       at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:44)
       at androidx.compose.foundation.layout.FillModifier.measure-3p2s80s(Size.kt:658)
       at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:53)
       at androidx.compose.ui.node.LayoutNode$performMeasure$1.invoke(LayoutNode.kt:1388)
       at androidx.compose.ui.node.LayoutNode$performMeasure$1.invoke(LayoutNode.kt:1387)
       at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:2063)
       at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:112)
       at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:78)
       at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:66)
       at androidx.compose.ui.node.LayoutNode.performMeasure-BRTryo0$ui_release(LayoutNode.kt:1387)
       at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
       at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:75)
       at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1331)
       at androidx.compose.ui.layout.RootMeasurePolicy.measure-3p2s80s(RootMeasurePolicy.kt:38)
       at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:44)
       at androidx.compose.ui.node.LayoutNode$performMeasure$1.invoke(LayoutNode.kt:1388)
       at androidx.compose.ui.node.LayoutNode$performMeasure$1.invoke(LayoutNode.kt:1387)
       at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:2063)
       at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:112)
       at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:78)
       at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:66)
       at androidx.compose.ui.node.LayoutNode.performMeasure-BRTryo0$ui_release(LayoutNode.kt:1387)
       at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
       at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui_release(LayoutNode.kt:1341)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.doRemeasure-sdFAvZA(MeasureAndLayoutDelegate.kt:185)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.remeasureAndRelayoutIfNeeded(MeasureAndLayoutDelegate.kt:274)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.access$remeasureAndRelayoutIfNeeded(MeasureAndLayoutDelegate.kt:38)
       at androidx.compose.ui.node.MeasureAndLayoutDelegate.measureAndLayout(MeasureAndLayoutDelegate.kt:208)
       at androidx.compose.ui.platform.AndroidComposeView.onMeasure(AndroidComposeView.android.kt:789)
       at android.view.View.measure(View.java:27709)
       at androidx.compose.ui.platform.AbstractComposeView.internalOnMeasure$ui_release(ComposeView.android.kt:298)
       at androidx.compose.ui.platform.AbstractComposeView.onMeasure(ComposeView.android.kt:285)
       at android.view.View.measure(View.java:27709)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7352)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:27709)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7352)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
       at android.view.View.measure(View.java:27709)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7352)
       at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:733)
       at com.google.android.material.appbar.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:95)
       at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1556)
       at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:803)
       at android.view.View.measure(View.java:27709)
       at android.widget.RelativeLayout.measureChild(RelativeLayout.java:696)
       at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:499)
       at android.view.View.measure(View.java:27709)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7352)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:145)
       at android.view.View.measure(View.java:27709)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7352)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
       at android.view.View.measure(View.java:27709)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7352)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:27709)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7352)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
       at android.view.View.measure(View.java:27709)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7352)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at com.android.internal.policy.DecorView.onMeasure(DecorView.java:1366)
       at android.view.View.measure(View.java:27709)
       at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:4711)
       at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:3301)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3607)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2991)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10665)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1301)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1309)
       at android.view.Choreographer.doCallbacks(Choreographer.java:923)
       at android.view.Choreographer.doFrame(Choreographer.java:852)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1283)
       at android.os.Handler.handleCallback(Handler.java:942)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8741)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

有人遇到同样的问题吗?我们如何解决这个问题?我们收到了146个崩溃影响15个用户(所有在三星Galaxy S22 Ultra + Android 13)

zaq34kh6

zaq34kh61#

我已经解决了我自己的问题。我发现崩溃是由字体设置中的粗体设置引起的。

当启用粗体时,应用程序崩溃。搜索我的代码,我发现我在下面的代码中传递了一个字体系列XML:

val DinPro = FontFamily(
Font(R.font.dinpro_light, FontWeight.Light),
Font(R.font.dinpro_medium, FontWeight.Medium),
Font(R.font.dinpro_regular, FontWeight.Normal),
Font(R.font.dinpro_bold, FontWeight.Bold))

所以R.font.dinpro_bold看起来像这样:

<font-family xmlns:app="http://schemas.android.com/apk/res-auto">
<font app:font="@font/dinpro_bold_lib" />
</font-family>

我已经更改了代码,现在使用font-resource而不是font-family资源:

val DinPro = FontFamily(
Font(R.font.dinpro_light_lib, FontWeight.Light),
Font(R.font.dinpro_medium_lib, FontWeight.Medium),
Font(R.font.dinpro_regular_lib, FontWeight.Normal),
Font(R.font.dinpro_bold_lib, FontWeight.Bold))

现在一切正常!

相关问题