Repository navigation
Description
Steps to reproduce
flutter create --platforms android repro && cd reproflutter pub add shared_preferences(resolvesshared_preferences2.5.5 andshared_preferences_android2.5.0)- Replace
lib/main.dartwith the code sample below. flutter build apk --release(R8 is on by default for release builds) and install/run the APK on a device or emulator, e.g.flutter run --release.
Expected results
The app opens the preferences, shows the first frame and counts launches, as it does with shared_preferences_android 2.4.28 and as it does in debug and profile builds with 2.5.0.
Actual results
SharedPreferencesWithCache.create() throws at start in the release build, so runApp() is never reached and the app stays on the splash screen. Debug and profile builds work, and iOS is not affected.
shared_preferences_android 2.5.0 calls its Kotlin code through JNI (flutter/packages#12329). The JNI bindings of the plugin and package:jni 1.1.0 (lib/src/kotlin.dart) look up Kotlin classes by name: kotlin.coroutines.Continuation, kotlin.Unit, kotlin.Result, kotlin.Result$Failure, kotlin.coroutines.intrinsics.CoroutineSingletons and kotlin.coroutines.intrinsics.IntrinsicsKt. R8 renames them, and neither the plugin (it has no consumer ProGuard rules) nor jni (its consumer-rules.pro keeps only com.github.dart_lang.jni.**) keeps them. SharedPreferencesAsyncApiRegistrar itself survives thanks to @Keep (flutter/packages#13151), but R8 rewrites the descriptor of its getAll with the renamed Continuation, so the descriptor that the Dart bindings use no longer exists. From build/app/outputs/mapping/release/mapping.txt:
kotlin.coroutines.Continuation -> o1.d:
Workarounds that make the release build work:
- constrain the Android implementation:
flutter pub add 'shared_preferences_android:>=2.4.28 <2.5.0', or - keep the Kotlin classes in
android/app/proguard-rules.pro:
-keep class kotlin.Unit { *; }
-keep class kotlin.Result { *; }
-keep class kotlin.Result$Failure { *; }
-keep class kotlin.coroutines.Continuation { *; }
-keep class kotlin.coroutines.intrinsics.CoroutineSingletons { *; }
-keep class kotlin.coroutines.intrinsics.IntrinsicsKt { *; }
Related: #193880 (closed; the generated classes got @Keep, and its PR notes that the Kotlin rules stay needed until jni ships them) and dart-lang/native#3732 (open; jni should keep these classes).
Code sample
Code sample
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
final preferences = await SharedPreferencesWithCache.create(
cacheOptions: const SharedPreferencesWithCacheOptions(),
);
final launches = (preferences.getInt('launches') ?? 0) + 1;
await preferences.setInt('launches', launches);
debugPrint('launches=$launches');
runApp(MaterialApp(home: Scaffold(body: Center(child: Text('$launches')))));
}Screenshots or Video
No response
Logs
Logs
E flutter: Unhandled Exception: PlatformException(PlatformException, java.lang.NoSuchMethodError: no non-static method "Lio/flutter/plugins/sharedpreferences/SharedPreferencesAsyncApiRegistrar;.getAll(Ljava/util/List;Lio/flutter/plugins/sharedpreferences/SharedPreferencesPigeonOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;"
...
#3 SharedPreferencesWithCache.createSeen on an Android 17 (API 37) arm64 emulator with an arm64 release APK.
Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.44.2, on macOS 27.0.1 26A434 darwin-arm64, locale en-US)
• Framework revision c9a6c48423 (4 months ago), 2026-06-10 15:52:41 -0700
• Engine revision 77e2e94772
• Dart version 3.12.2
[✓] Android toolchain - develop for Android devices (Android SDK version 37.0.0)
• Platform android-37.0, build-tools 37.0.0
• Java version OpenJDK Runtime Environment (build 21.0.10+-117844308-b1163.108)
[✓] Xcode - develop for iOS and macOS (Xcode 27.1)
Activity
Keep shared_preferences_android below 2.5.0 to fix release startup
saurabh-mirajkar commentedon Oct 19, 2026
@ybeshkarov Thanks for the report. I was able to reproduce this on a Pixel 6 running Android 17 (API 37) and latest Flutter stable (3.47.7).
With
shared_preferences_android 2.5.0, debug and profile builds work, but the release build stays on the splash screen and throws the reportedNoSuchMethodError.Pinning
shared_preferences_androidto2.4.28makes the release build work in the same reproduction, confirming the regression between these versions in my test environment.Labelling this and routing it to the Android team for evaluation.
Related: #193880 and dart-lang/native#3732.
ybeshkarov commentedon Oct 19, 2026
Thanks for confirming, @saurabh-mirajkar.
I've opened a fix for this: flutter/packages#13311. It adds
android/consumer-rules.protoshared_preferences_androidwith the six keep rules from Step 5 of Pigeon's native interop guide and lists it inconsumerProguardFiles, so R8 applies them in every app that uses the plugin. With adependency_overridespath to that branch, the reproduction above starts in a release build, and bothSharedPreferencesAsyncand the legacySharedPreferencesAPI work. The rules have a TODO to remove them oncejniships them (dart-lang/native#3732).The PR has the
missing-testslabel. As far as I can tell, no CI target in flutter/packages runs a release build of a plugin, so I asked for a test exemption there. If a release-mode test fits somewhere, I’m happy to add one.fix: startup NoSuchMethodError from shared_preferences_android 2.5.0 …
Fix Android splash hang: hold shared_preferences_android <2.5.0, keep…
13 remaining items
ybeshkarov commentedon Oct 21, 2026
The fix is merged as 2.5.2, but the release run for it failed, so it isn't on pub.dev yet. Until it is, pin
shared_preferences_android: 2.4.28independency_overridesor add the keep rules from flutter/packages#13311 toandroid/app/proguard-rules.pro.fix(android): keep Kotlin classes that package:jni looks up by name
fix(android): 修复 release 启动永久白屏(shared_preferences_android 2.5.0 JNI×R8)
nimr77 commentedon Oct 21, 2026
This issue has been closed but it still in the package, will be any new update
ybeshkarov commentedon Oct 21, 2026
@nimr77 The issue closed automatically when the fix (flutter/packages#13311) was merged, since issues here close on merge rather than on release. The job that publishes 2.5.2 to pub.dev failed on a CI infrastructure problem, and it's still early morning in the US for the team, so we're waiting for someone to re-run it. Until 2.5.2 is out, the workarounds from my comment above still work: pin
shared_preferences_android: 2.4.28independency_overrides, or add the keep rules from flutter/packages#13311 toandroid/app/proguard-rules.pro.nimr77 commentedon Oct 21, 2026
@ybeshkarov
Thanks, yes I used the work around its working, perfectly for our apps.
fix(deps): pin shared_preferences_android below 2.5.0
ybeshkarov commentedon Oct 22, 2026
shared_preferences_android 2.5.2 with the fix is now on pub.dev. If you pinned 2.4.28 in
dependency_overrides, remove the override, runflutter pub upgrade, and check thatpubspec.lockhas 2.5.2. The keep rules inproguard-rules.proaren't needed anymore either.chore: bump shared_preferences_android to 2.5.3
fix(android): resolve startup failure caused by shared_preferences_an…
mobile: pin shared_preferences_android to 2.4.28; storage can no long…
github-actions commentedon Nov 5, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.