Skip to content

[shared_preferences] switch to ffi/jni pigeon - #12329

Draft
tarrinneal wants to merge 3 commits into
flutter:mainfrom
tarrinneal:spffijni
Draft

[shared_preferences] switch to ffi/jni pigeon#12329
tarrinneal wants to merge 3 commits into
flutter:mainfrom
tarrinneal:spffijni

Conversation

@tarrinneal

Copy link
Copy Markdown
Contributor

for example

@tarrinneal

Copy link
Copy Markdown
Contributor Author

@stuartmorgan-g this is a working example of switching to ffi/jni pigeon. the pr contains all of the pigeon changes, but you can just look at the shared preferences stuff

@tarrinneal tarrinneal added the CICD Run CI/CD label Aug 4, 2026

@stuartmorgan-g stuartmorgan-g left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The iOS part generally looks good, but one question on the binary file. The Android part I have more questions about the structure of main package vs example package.

@@ -52,3 +52,89 @@ dependencies {
androidTestImplementation("androidx.test.espresso:espresso-core:3.2.0")
api("androidx.test:core:1.4.0")
}
// Gradle stub for listing dependencies in JNIgen. If found in

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I know this isn't in our direct control, but something we should raise for long-term jnigen discussions: I worry about the maintenance of this code. It's in a user-controlled file, not a generated file, which means that if it needs to change in the future there will need to be some potentially non-trivial migration.

(On the other hand, that's also true of the Flutter plugin system itself.)

Comment thread packages/shared_preferences/shared_preferences_android/example/pubspec.yaml Outdated
Comment thread packages/shared_preferences/shared_preferences_android/pigeons/messages.dart Outdated

@stuartmorgan-g stuartmorgan-g left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The Android structure is looking good now! One significant remaining issue for actually adopting this PR, but that's not related to the Pigeon generation itself, so in terms of validating the other PR I think we're in good shape here. I'll start on what it looks like should be the final review of the Pigeon PR shortly!

sdk: flutter
integration_test:
sdk: flutter
jnigen: ^0.17.0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this change still needed?

@HostApi()
abstract class SharedPreferencesApi {
/// Removes property from shared preferences data set.
@TaskQueue(type: TaskQueueType.serialBackgroundThread)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

All the implementations on the native side need to change to manually dispatch to a background thread (like they did before we had task queues, but presumably it's easier in Kotlin) so that we aren't regressing the old issue of doing file access on the main thread.

@HostApi()
abstract class SharedPreferencesAsyncApi {
/// Adds property to shared preferences data set of type `bool`.
@TaskQueue(type: TaskQueueType.serialBackgroundThread)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same for this class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants