Skip to content

Commit fa5d4e2

Browse files
committed
Catch NoSuchFieldError in AccessibilityBridge.setBoldTextFlag
Vendor-modified Android 11 ROMs (e.g., OnePlus) may report SDK_INT >= 31 but lack the Configuration.fontWeightAdjustment field added in AOSP API 31. The runtime integer guard is insufficient because the JVM resolves field references at method call time. Wrap the access in try/catch to gracefully degrade rather than crashing at app startup. Fixes flutter#184286
1 parent 3688546 commit fa5d4e2

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,19 @@ private void setBoldTextFlag() {
658658
if (rootAccessibilityView == null || rootAccessibilityView.getResources() == null) {
659659
return;
660660
}
661-
int fontWeightAdjustment =
662-
rootAccessibilityView.getResources().getConfiguration().fontWeightAdjustment;
663-
boolean shouldBold =
664-
fontWeightAdjustment != Configuration.FONT_WEIGHT_ADJUSTMENT_UNDEFINED
665-
&& fontWeightAdjustment >= BOLD_TEXT_WEIGHT_ADJUSTMENT;
661+
boolean shouldBold;
662+
try {
663+
int fontWeightAdjustment =
664+
rootAccessibilityView.getResources().getConfiguration().fontWeightAdjustment;
665+
shouldBold =
666+
fontWeightAdjustment != Configuration.FONT_WEIGHT_ADJUSTMENT_UNDEFINED
667+
&& fontWeightAdjustment >= BOLD_TEXT_WEIGHT_ADJUSTMENT;
668+
} catch (NoSuchFieldError e) {
669+
// Some vendor-modified Android runtimes report SDK_INT >= 31 but ship a
670+
// Configuration class without the fontWeightAdjustment field (added in API 31).
671+
// Gracefully degrade rather than crashing at app startup.
672+
shouldBold = false;
673+
}
666674

667675
if (shouldBold) {
668676
accessibilityFeatureFlags |= AccessibilityFeature.BOLD_TEXT.value;

0 commit comments

Comments
 (0)