Fix AccessibilityBridge startup crash on vendor-modified Android#184630
Conversation
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
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
There was a problem hiding this comment.
Code Review
This pull request introduces a try-catch block in AccessibilityBridge.java to prevent crashes on vendor-modified Android runtimes where the fontWeightAdjustment field might be missing despite the reported SDK version. Feedback suggests catching the broader LinkageError for improved robustness and initializing the shouldBold variable to false to simplify the logic.
| boolean shouldBold; | ||
| try { | ||
| int fontWeightAdjustment = | ||
| rootAccessibilityView.getResources().getConfiguration().fontWeightAdjustment; | ||
| shouldBold = | ||
| fontWeightAdjustment != Configuration.FONT_WEIGHT_ADJUSTMENT_UNDEFINED | ||
| && fontWeightAdjustment >= BOLD_TEXT_WEIGHT_ADJUSTMENT; | ||
| } catch (NoSuchFieldError e) { | ||
| // Some vendor-modified Android runtimes report SDK_INT >= 31 but ship a | ||
| // Configuration class without the fontWeightAdjustment field (added in API 31). | ||
| // Gracefully degrade rather than crashing at app startup. | ||
| shouldBold = false; | ||
| } |
There was a problem hiding this comment.
While NoSuchFieldError specifically addresses the reported crash, using the broader LinkageError provides better robustness against other potential binary incompatibilities (such as IncompatibleClassChangeError or VerifyError) that might occur on vendor-modified runtimes. Additionally, initializing shouldBold to false by default simplifies the logic and ensures the variable is always in a safe state if an error occurs during the evaluation of the try block.
boolean shouldBold = false;
try {
int fontWeightAdjustment =
rootAccessibilityView.getResources().getConfiguration().fontWeightAdjustment;
shouldBold =
fontWeightAdjustment != Configuration.FONT_WEIGHT_ADJUSTMENT_UNDEFINED
&& fontWeightAdjustment >= BOLD_TEXT_WEIGHT_ADJUSTMENT;
} catch (LinkageError e) {
// Some vendor-modified Android runtimes report SDK_INT >= 31 but ship a
// Configuration class without the fontWeightAdjustment field (added in API 31).
// Gracefully degrade rather than crashing at app startup.
}… false - Catch broader LinkageError instead of NoSuchFieldError to handle other binary incompatibilities on vendor-modified runtimes - Initialize shouldBold to false so catch block needs no assignment
| fontWeightAdjustment != Configuration.FONT_WEIGHT_ADJUSTMENT_UNDEFINED | ||
| && fontWeightAdjustment >= BOLD_TEXT_WEIGHT_ADJUSTMENT; | ||
| } catch (LinkageError e) { | ||
| // Some vendor-modified Android runtimes report SDK_INT >= 31 but ship a |
There was a problem hiding this comment.
Do you know which venders does this?
There was a problem hiding this comment.
Yes — both the Flutter Crashlytics data on #184286 and the AOSP report b/353988277 that AndroidX Compose fixed reference the same two devices on Android 11:
- OnePlus 8 Pro / Android 11 — 95 fatal events in 90 days, 100% of @lukemmtt's Crashlytics reports (app versions 9.4.2, 9.4.4, 9.4.7, 9.4.13)
- Google Pixel 4a / Android 11 — explicitly named in AOSP b/353988277, identical stack:
NoSuchFieldError: No instance field fontWeightAdjustment of type I in class Landroid/content/res/Configurationending inAndroidFontResolveInterceptor
Pixel 4a is stock Google, so calling this "vendor-modified" was imprecise on my part. The unifying factor is ART on Android 11, not the OEM: the class verifier eagerly resolves the API-31 Configuration.fontWeightAdjustment field reference when loading AccessibilityBridge, so the runtime SDK_INT >= 31 guard at the call site runs too late to prevent the throw. AndroidX Compose hit the identical symptom on the same two devices and landed the equivalent try { ... } catch (LinkageError) { ... } mitigation in commit f7d312d (AndroidFontResolveInterceptor.android.kt, "Improve fontWeightAdjustment @RequiresApi guards"). The Chromium class_verification_failures.md doc explains the underlying ART behavior in detail — notably that @RequiresApi is lint-only and does not prevent the verifier from resolving the reference.
Just pushed 8ece0b1 which rewrites the comment to name those devices, cite b/353988277, and note that the workaround can be removed when Flutter drops Android 11 support.
If you'd prefer to match the AndroidX pattern more faithfully now rather than rely on the catch, the access could be hoisted into a private static Api31Impl helper class annotated with @RequiresApi(31) so the verifier never encounters the field reference when loading AccessibilityBridge on API 30 builds in the first place. Happy to do that as a follow-up commit if you'd prefer that direction over the defensive catch.
There was a problem hiding this comment.
thanks for the detailed reply, the updated comment should address my concern
Per review at flutter#184630 (chunhtai), clarify the comment to name the devices where this crash has been observed (Pixel 4a and OnePlus 8 Pro, both on Android 11) and cite AndroidX Compose's identical fix (AOSP b/353988277) so a future reader can assess when the workaround can be removed. Note that "vendor-modified" was imprecise since the Pixel 4a is stock Google; the root cause is ART class verification on Android 11 eagerly resolving the API 31 field reference before the SDK_INT >= 31 guard runs.
chunhtai
left a comment
There was a problem hiding this comment.
LGTM, but should wait for someone from android team to approve as well
Per review at flutter#184630 (jesswrd), replace the defensive try/catch LinkageError with the @RequiresApi(31) helper class pattern from the issue's proposed direction, mirroring AndroidX Compose's fix (AOSP b/353988277). Moving the Configuration.fontWeightAdjustment field access into a private static Api31Impl inner class prevents ART's class verifier from resolving the API-31 field reference when loading AccessibilityBridge on older API levels. The @DoNotInline annotation prevents R8 from inlining the method back into the outer class, which would defeat the class isolation.
|
autosubmit label was removed for flutter/flutter/184630, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR. |
|
autosubmit label was removed for flutter/flutter/184630, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR. |
|
autosubmit label was removed for flutter/flutter/184630, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR. |
|
autosubmit label was removed for flutter/flutter/184630, because - The status or check suite Mac_arm64 build_tests_4_5 has failed. Please fix the issues identified (or deflake) before re-applying this label. |
flutter/flutter@f3a4b98...c8f2f16 2026-05-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Flutter GPU] Add explicit draw counts (#186639)" (flutter/flutter#187170) 2026-05-27 engine-flutter-autoroll@skia.org Roll Dart SDK from 7dcea971af6b to f3db7b7d9801 (2 revisions) (flutter/flutter#187144) 2026-05-27 bdero@google.com [Flutter GPU] Add explicit draw counts (flutter/flutter#186639) 2026-05-27 engine-flutter-autoroll@skia.org Roll Skia from f9db7748563e to fa944af10f91 (1 revision) (flutter/flutter#187139) 2026-05-27 bdero@google.com [Flutter GPU] Flutter GPU ShaderLibrary in-place reload for shader hot reload (flutter/flutter#186793) 2026-05-27 engine-flutter-autoroll@skia.org Roll Skia from a692cbf38952 to f9db7748563e (8 revisions) (flutter/flutter#187135) 2026-05-27 burak.karahan@mail.ru Use local semantics tester in Material button tests (flutter/flutter#186667) 2026-05-27 rmolivares@renzo-olivares.dev Filter out `a: text input` from `team-framework` PR triage (flutter/flutter#187129) 2026-05-27 bkonyi@google.com [Engine] Fix silent buffer mismatch bug in FML Win32 CommandLineFromPlatform (flutter/flutter#187120) 2026-05-27 srawlins@google.com examples: Remove unused parameters (flutter/flutter#185819) 2026-05-27 116356835+AbdeMohlbi@users.noreply.github.com Remove another `String.valueOf` (flutter/flutter#186628) 2026-05-27 alex.medinsh@gmail.com Print trace when skipping flavor-specific and platform-specific assets (flutter/flutter#187045) 2026-05-26 adilhanney@disroot.org Fix `InteractiveViewer` memory leak from undisposed `CurvedAnimation`s (flutter/flutter#185826) 2026-05-26 meylis@divine.video Fix AccessibilityBridge startup crash on vendor-modified Android (flutter/flutter#184630) 2026-05-26 keertip@users.noreply.github.com Update data driven fixes docs (flutter/flutter#186217) 2026-05-26 ahmedsameha1@gmail.com Add more 0x0 size tests part10 (flutter/flutter#186201) 2026-05-26 46920873+gabrimatic@users.noreply.github.com Disable spell check for obscured text (flutter/flutter#186329) 2026-05-26 chris@bracken.jp [iOS] Migrate VSyncClient and DisplayLinkManager to Swift (flutter/flutter#187001) 2026-05-26 bkonyi@google.com [flutter_tools, devicelab] Add safety filesystem guard to tests (flutter/flutter#186748) 2026-05-26 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from Itd2Jq_ZIABH2rW7B... to k9EizfEGJO4WwQN9-... (flutter/flutter#187115) 2026-05-26 engine-flutter-autoroll@skia.org Roll Dart SDK from 00e625453c43 to 7dcea971af6b (1 revision) (flutter/flutter#187117) 2026-05-26 rmacnak@google.com Remove use of deprecated copy_trees. (flutter/flutter#187091) 2026-05-26 15619084+vashworth@users.noreply.github.com Use resolved implementation plugins with SwiftPM (flutter/flutter#187097) 2026-05-26 engine-flutter-autoroll@skia.org Roll Skia from 27a819894f7c to a692cbf38952 (3 revisions) (flutter/flutter#187109) 2026-05-26 engine-flutter-autoroll@skia.org Roll Packages from 69cf959 to fc795e5 (4 revisions) (flutter/flutter#187114) 2026-05-26 mvincentong@gmail.com Handle simctl process exceptions during discovery (flutter/flutter#186501) 2026-05-26 mvincentong@gmail.com Clarify precache enabled platforms help (flutter/flutter#186878) 2026-05-26 bkonyi@google.com [tool] Refactor artifacts.dart to use enhanced enums and reduce duplication (flutter/flutter#187063) 2026-05-26 jason-simmons@users.noreply.github.com Build script updates for syncing engine sources and building artifacts on linux-arm64 (flutter/flutter#186917) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC boetger@google.com,stuartmorgan@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
|
Would the release team consider a stable cherry-pick of this fix (#184630, fixes #184286)? Up front: this isn't a regression from a recent release — the unguarded Impacted Users Impact Description Workaround Risk Test Coverage Validation Steps |
…r#11795) flutter/flutter@f3a4b98...c8f2f16 2026-05-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Flutter GPU] Add explicit draw counts (#186639)" (flutter/flutter#187170) 2026-05-27 engine-flutter-autoroll@skia.org Roll Dart SDK from 7dcea971af6b to f3db7b7d9801 (2 revisions) (flutter/flutter#187144) 2026-05-27 bdero@google.com [Flutter GPU] Add explicit draw counts (flutter/flutter#186639) 2026-05-27 engine-flutter-autoroll@skia.org Roll Skia from f9db7748563e to fa944af10f91 (1 revision) (flutter/flutter#187139) 2026-05-27 bdero@google.com [Flutter GPU] Flutter GPU ShaderLibrary in-place reload for shader hot reload (flutter/flutter#186793) 2026-05-27 engine-flutter-autoroll@skia.org Roll Skia from a692cbf38952 to f9db7748563e (8 revisions) (flutter/flutter#187135) 2026-05-27 burak.karahan@mail.ru Use local semantics tester in Material button tests (flutter/flutter#186667) 2026-05-27 rmolivares@renzo-olivares.dev Filter out `a: text input` from `team-framework` PR triage (flutter/flutter#187129) 2026-05-27 bkonyi@google.com [Engine] Fix silent buffer mismatch bug in FML Win32 CommandLineFromPlatform (flutter/flutter#187120) 2026-05-27 srawlins@google.com examples: Remove unused parameters (flutter/flutter#185819) 2026-05-27 116356835+AbdeMohlbi@users.noreply.github.com Remove another `String.valueOf` (flutter/flutter#186628) 2026-05-27 alex.medinsh@gmail.com Print trace when skipping flavor-specific and platform-specific assets (flutter/flutter#187045) 2026-05-26 adilhanney@disroot.org Fix `InteractiveViewer` memory leak from undisposed `CurvedAnimation`s (flutter/flutter#185826) 2026-05-26 meylis@divine.video Fix AccessibilityBridge startup crash on vendor-modified Android (flutter/flutter#184630) 2026-05-26 keertip@users.noreply.github.com Update data driven fixes docs (flutter/flutter#186217) 2026-05-26 ahmedsameha1@gmail.com Add more 0x0 size tests part10 (flutter/flutter#186201) 2026-05-26 46920873+gabrimatic@users.noreply.github.com Disable spell check for obscured text (flutter/flutter#186329) 2026-05-26 chris@bracken.jp [iOS] Migrate VSyncClient and DisplayLinkManager to Swift (flutter/flutter#187001) 2026-05-26 bkonyi@google.com [flutter_tools, devicelab] Add safety filesystem guard to tests (flutter/flutter#186748) 2026-05-26 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from Itd2Jq_ZIABH2rW7B... to k9EizfEGJO4WwQN9-... (flutter/flutter#187115) 2026-05-26 engine-flutter-autoroll@skia.org Roll Dart SDK from 00e625453c43 to 7dcea971af6b (1 revision) (flutter/flutter#187117) 2026-05-26 rmacnak@google.com Remove use of deprecated copy_trees. (flutter/flutter#187091) 2026-05-26 15619084+vashworth@users.noreply.github.com Use resolved implementation plugins with SwiftPM (flutter/flutter#187097) 2026-05-26 engine-flutter-autoroll@skia.org Roll Skia from 27a819894f7c to a692cbf38952 (3 revisions) (flutter/flutter#187109) 2026-05-26 engine-flutter-autoroll@skia.org Roll Packages from 69cf959 to fc795e5 (4 revisions) (flutter/flutter#187114) 2026-05-26 mvincentong@gmail.com Handle simctl process exceptions during discovery (flutter/flutter#186501) 2026-05-26 mvincentong@gmail.com Clarify precache enabled platforms help (flutter/flutter#186878) 2026-05-26 bkonyi@google.com [tool] Refactor artifacts.dart to use enhanced enums and reduce duplication (flutter/flutter#187063) 2026-05-26 jason-simmons@users.noreply.github.com Build script updates for syncing engine sources and building artifacts on linux-arm64 (flutter/flutter#186917) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC boetger@google.com,stuartmorgan@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…tter#184630) ## Summary - Some vendor-modified Android runtimes report `SDK_INT >= 31` but ship a `Configuration` class without the `fontWeightAdjustment` field (added in API 31), causing a `NoSuchFieldError` crash at app startup in `AccessibilityBridge.setBoldTextFlag` - Wrap the `fontWeightAdjustment` access in a try/catch for `NoSuchFieldError`, gracefully defaulting to non-bold text instead of crashing ## Changes - `engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java`: Added try/catch around `fontWeightAdjustment` field access with fallback to `shouldBold = false` Fixes flutter#184286 --------- Co-authored-by: jesswrd <jesswon@google.com> Co-authored-by: Matt Boetger <matt.boetger@gmail.com> Co-authored-by: Camille Simon <43054281+camsim99@users.noreply.github.com>
Summary
SDK_INT >= 31but ship aConfigurationclass without thefontWeightAdjustmentfield (added in API 31), causing aNoSuchFieldErrorcrash at app startup inAccessibilityBridge.setBoldTextFlagfontWeightAdjustmentaccess in a try/catch forNoSuchFieldError, gracefully defaulting to non-bold text instead of crashingChanges
engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java: Added try/catch aroundfontWeightAdjustmentfield access with fallback toshouldBold = falseFixes #184286