Skip to content

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

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

[shared_preferences] switch to ffi/jni pigeon#12329
tarrinneal wants to merge 4 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.

channel.setMessageHandler(null)
}
}
error("SharedPreferencesApi has not been set")

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.

A minor nit: should we say "registered" instead of "set" to connect this more clearly to the register method that needs to be called?

@@ -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.)

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.

Why do these files exist in the example app? Is this cruft from an earlier mistake in generation path?

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.

It feels weird to have these in the example rather than the main plugin. Can't we have them in the main plugin package, and use androidExample directory to point into the subdirectory?

@@ -9,12 +9,8 @@ environment:
dependencies:
flutter:
sdk: flutter
jni: ^1.0.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.

This worries me; having to make production dependency changes to the example means that we are not testing the same configuration that everyone using shared_preferences will have, which could mask mistakes.

Is this only because the tool/ directory is part of the example rather than the main bundle?

Directory.current = Platform.script.resolve('../..').toFilePath();
await generateJniBindings(
Config(
androidSdkConfig: AndroidSdkConfig(addGradleDeps: true, androidExample: './'),

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 androidExample correct here? If so that seems pretty confusing; how can the example be the current directory rather than example/?

@@ -12,7 +12,7 @@ Wraps NSUserDefaults, providing a persistent store for simple key-value pairs.
s.license = { :type => 'BSD', :file => '../LICENSE' }
s.author = { 'Flutter Team' => 'flutter-dev@googlegroups.com' }
s.source = { :http => 'https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences_foundation' }
s.source_files = 'shared_preferences_foundation/Sources/shared_preferences_foundation/**/*.swift'
s.source_files = 'shared_preferences_foundation/Sources/**/*.{swift,m,h}'

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.

Are we still expecting there to be .m code generated, or just the .o?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the .m file isn't always generated, this api surface is simple enough that it isn't needed. The skill currently says to add both since it will always work. Do you think it's a bad idea?

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