Skip to content

[shared_preferences_android] Fix web compilation of apps that import the package - #13380

Merged
auto-submit[bot] merged 1 commit into
flutter:mainfrom
mdebbar:shared-prefs-android-web-stub
Oct 22, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:mainfrom
mdebbar:shared-prefs-android-web-stub

Conversation

@mdebbar

@mdebbar mdebbar commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Since 2.5.0 (#12329), package:shared_preferences_android/shared_preferences_android.dart transitively imports package:jni, which needs dart:ffi. So any app that imports it fails to compile for web, even if it only uses SharedPreferencesAsyncAndroidOptions the way the shared_preferences README shows. This currently breaks shared_preferences/example in the web unit test shards on every Flutter roll PR:

jni-1.1.0/lib/src/jni.dart:5:8: Error: Dart library 'dart:ffi' is not available on this platform.

Example CI failures:

This uses the same approach as path_provider_android: the library exports a stub of the plugin classes when dart.library.ffi isn't available, and the option types move to their own file that doesn't depend on FFI. The package's own tests now import src/shared_preferences_android_real.dart directly, since the analyzer resolves the conditional export to the stub.

Test coverage comes from the existing shared_preferences/example web tests, which import this library and fail to compile without this change.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Oct 22, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes web compilation for apps importing shared_preferences_android by conditionally exporting a stub implementation on platforms without FFI support and moving Android-specific options to a separate file. A review comment notes that importing src/ files directly in the example integration tests violates the implementation_imports lint rule and suggests using the public package entry point instead.

@tarrinneal tarrinneal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable. thanks for fixing this

@tarrinneal tarrinneal added the emergency Override tree-status signal (land even with closed tree), combine with the autosubmit label. label Oct 22, 2026
@flutter-dashboard

Copy link
Copy Markdown

Detected the emergency label.

If you add the autosubmit label, the bot will wait until all presubmits pass but ignore the tree status, allowing fixes for tree breakages while still validating that they don't break any existing presubmits.

The "Merge" button is also unlocked. To bypass presubmits as well as the tree status, press the GitHub "Add to Merge Queue".

@tarrinneal tarrinneal added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 22, 2026
@auto-submit
auto-submit Bot merged commit ea7e031 into flutter:main Oct 22, 2026
11 of 12 checks passed
bkonyi pushed a commit to bkonyi/flutter that referenced this pull request Oct 23, 2026
flutter/packages@93baed9...108dad0

2026-10-22 [email protected] [material_ui]
Migrate M3 IconButton template to use new gen_defaults
(flutter/packages#12922)
2026-10-22 [email protected] [material_ui]
Migrate M3 NavigationBar template to use new gen_defaults
(flutter/packages#13067)
2026-10-22 [email protected] [material_ui]
Remove obsolete `SurfaceTint` defaults template (flutter/packages#13276)
2026-10-22 [email protected] [material_ui]
Migrate M3 Radio template to use new gen_defaults
(flutter/packages#13210)
2026-10-22 [email protected] [material_ui]
Migrate M3 NavigationDrawer template to use new gen_defaults
(flutter/packages#13068)
2026-10-22 [email protected] [image_picker_ios] PR 3/5 Split
SPM packaging and migrate the plugin class to Swift
(flutter/packages#13235)
2026-10-22 [email protected] [ci] Increase check-discovery timeout
in release workflows (flutter/packages#13392)
2026-10-22 [email protected] [material_ui]
Migrate M3 `Switch` template to use new gen_defaults
(flutter/packages#13274)
2026-10-22 [email protected] [material_ui]
Migrate M3 PopupMenu template to use new gen_defaults
(flutter/packages#13209)
2026-10-22 [email protected] [material_ui] Add day and weekday
builders to CalendarDatePicker and showDatePicker
(flutter/packages#12587)
2026-10-22 [email protected] [material_ui]
Migrate M3 `SearchView` template to use new gen_defaults
(flutter/packages#13272)
2026-10-22 [email protected] [material_ui]
Migrate M3 `TextField` template to use new gen_defaults
(flutter/packages#13275)
2026-10-22 [email protected] [material_ui]
Migrate M3 RangeSlider template to use new gen_defaults
(flutter/packages#13215)
2026-10-22 [email protected] [go_router] Keep web
autocomplete focused in shell routes (flutter/packages#13348)
2026-10-22 [email protected] [shared_preferences_android] Fix web
compilation of apps that import the package (flutter/packages#13380)
2026-10-22 [email protected] [material_ui]
Migrate M3 NavigationRail template to use new gen_defaults
(flutter/packages#13069)
2026-10-22 [email protected] [material_ui]
Migrate M3 SearchBar template to use new gen_defaults
(flutter/packages#13216)
2026-10-22 [email protected] [material_ui] Fix for time picker error
in locales that do not use Latin digits (flutter/packages#13035)
2026-10-22 [email protected] [material_ui]
Fix MenuAnchor scrollbar safe-area padding (flutter/packages#12470)
2026-10-22 [email protected] [material_ui] Document Material 3
fallback for Divider.color and VerticalDivider.color
(flutter/packages#12967)
2026-10-22 [email protected]
[material_ui] Migrate M3 tabs template to use new gen_defaults
(flutter/packages#13139)
2026-10-22 [email protected] [material_ui]
Migrate M3 progress indicator defaults to new gen_defaults
(flutter/packages#13026)
2026-10-22 [email protected] [google_sign_in] Convert the iOS
example app and UI tests to Swift (flutter/packages#13271)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
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
auto-submit Bot pushed a commit that referenced this pull request Oct 27, 2026
…rt the package (#13447)

Since 2.6.0 (#12329), `package:shared_preferences_foundation/shared_preferences_foundation.dart` transitively imports `dart:ffi` and `package:objective_c`, causing multi-platform apps that import it (for example to use `SharedPreferencesAsyncFoundationOptions`) to fail compilation on web. This currently breaks `shared_preferences/example` web drive tests in CI.

Following the same approach as `shared_preferences_android` in #13380, this conditionally exports a stub of the plugin classes when `dart.library.ffi` is unavailable and moves `SharedPreferencesAsyncFoundationOptions` into its own FFI-free file.
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
flutter/packages@93baed9...108dad0

2026-10-22 [email protected] [material_ui]
Migrate M3 IconButton template to use new gen_defaults
(flutter/packages#12922)
2026-10-22 [email protected] [material_ui]
Migrate M3 NavigationBar template to use new gen_defaults
(flutter/packages#13067)
2026-10-22 [email protected] [material_ui]
Remove obsolete `SurfaceTint` defaults template (flutter/packages#13276)
2026-10-22 [email protected] [material_ui]
Migrate M3 Radio template to use new gen_defaults
(flutter/packages#13210)
2026-10-22 [email protected] [material_ui]
Migrate M3 NavigationDrawer template to use new gen_defaults
(flutter/packages#13068)
2026-10-22 [email protected] [image_picker_ios] PR 3/5 Split
SPM packaging and migrate the plugin class to Swift
(flutter/packages#13235)
2026-10-22 [email protected] [ci] Increase check-discovery timeout
in release workflows (flutter/packages#13392)
2026-10-22 [email protected] [material_ui]
Migrate M3 `Switch` template to use new gen_defaults
(flutter/packages#13274)
2026-10-22 [email protected] [material_ui]
Migrate M3 PopupMenu template to use new gen_defaults
(flutter/packages#13209)
2026-10-22 [email protected] [material_ui] Add day and weekday
builders to CalendarDatePicker and showDatePicker
(flutter/packages#12587)
2026-10-22 [email protected] [material_ui]
Migrate M3 `SearchView` template to use new gen_defaults
(flutter/packages#13272)
2026-10-22 [email protected] [material_ui]
Migrate M3 `TextField` template to use new gen_defaults
(flutter/packages#13275)
2026-10-22 [email protected] [material_ui]
Migrate M3 RangeSlider template to use new gen_defaults
(flutter/packages#13215)
2026-10-22 [email protected] [go_router] Keep web
autocomplete focused in shell routes (flutter/packages#13348)
2026-10-22 [email protected] [shared_preferences_android] Fix web
compilation of apps that import the package (flutter/packages#13380)
2026-10-22 [email protected] [material_ui]
Migrate M3 NavigationRail template to use new gen_defaults
(flutter/packages#13069)
2026-10-22 [email protected] [material_ui]
Migrate M3 SearchBar template to use new gen_defaults
(flutter/packages#13216)
2026-10-22 [email protected] [material_ui] Fix for time picker error
in locales that do not use Latin digits (flutter/packages#13035)
2026-10-22 [email protected] [material_ui]
Fix MenuAnchor scrollbar safe-area padding (flutter/packages#12470)
2026-10-22 [email protected] [material_ui] Document Material 3
fallback for Divider.color and VerticalDivider.color
(flutter/packages#12967)
2026-10-22 [email protected]
[material_ui] Migrate M3 tabs template to use new gen_defaults
(flutter/packages#13139)
2026-10-22 [email protected] [material_ui]
Migrate M3 progress indicator defaults to new gen_defaults
(flutter/packages#13026)
2026-10-22 [email protected] [google_sign_in] Convert the iOS
example app and UI tests to Swift (flutter/packages#13271)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
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
auto-submit Bot pushed a commit that referenced this pull request Oct 29, 2026
…mported companion file (#13393)

Separates generated Dart native interop code (`dart:ffi`, `dart:io`, `package:jni`, `package:ffi`, `package:objective_c`, and `.ffi.dart`/`.jni.dart` bindings) into a companion `*.native_interop.g.dart` file that is conditionally imported (`if (dart.library.ffi)`) by the main `*.g.dart` file.

This allows the main generated `*.g.dart` file (data classes, enums, codecs, and method-channel APIs) to be imported on Web without failing `dart2js` / `dart2wasm` compilation due to transitive `dart:ffi` / `dart:io` imports (preventing the issue worked around in #13380).

## Pre-Review Checklist

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD emergency Override tree-status signal (land even with closed tree), combine with the autosubmit label. p: shared_preferences platform-android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants