Skip to content
All articles

6 min read

Fix the shared_preferences release build crash on Android

shared_preferences_android 2.5.0 keeps Flutter release builds on the splash screen. What causes the shared_preferences release build crash, and the 2.5.2 fix.

By Yevhen Beshkarov · Updated November 29, 2026

  • troubleshooting
  • android

Update, 22 October 2026: I found this bug by chance on the day 2.5.0 came out, and my pull request fixed it in shared_preferences_android 2.5.2. If you pinned the version with the first workaround below, remove the pin. The keep rules from the second can stay: they do no harm. Then run flutter pub upgrade shared_preferences_android and check that pubspec.lock has 2.5.2.

On 17 October 2026, shared_preferences_android 2.5.0 came out, and Flutter apps that use shared_preferences stopped starting in Android release builds. The app stays on the splash screen, and logcat has a NoSuchMethodError. Debug and profile builds work, and so does iOS, so a CI that builds only debug stays green. The cause is R8, which renames Kotlin classes that the new version looks up by name. Upgrading to shared_preferences_android 2.5.2 fixes the shared_preferences release build crash. If you can't upgrade yet, go back to the previous version or add six keep rules to the app.

NoSuchMethodError in SharedPreferencesAsyncApiRegistrar.getAll

With SharedPreferencesAsync or SharedPreferencesWithCache, the first call to the preferences throws:

Text
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;"

With the legacy SharedPreferences.getInstance(), the class in the message is SharedPreferencesApiRegistrar:

Text
PlatformException(PlatformException, java.lang.NoSuchMethodError: no non-static method "Lio/flutter/plugins/sharedpreferences/SharedPreferencesApiRegistrar;.getAll(Ljava/lang/String;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;"

When the app opens the preferences in main(), before runApp(), the future fails and runApp() never runs. The app keeps showing its splash screen, and no crash dialog comes up. An app that opens the preferences later fails on the screen that reads them.

When it fails: shared_preferences_android 2.5.0 and R8

In the app's directory, check which version pub resolved:

Shell
flutter pub deps | grep shared_preferences_android

This is your case if:

  • it prints shared_preferences_android 2.5.0 or 2.5.1. shared_preferences 2.5.5 allows any 2.x of shared_preferences_android from 2.3.4 on, so a flutter pub upgrade, or a first flutter pub get between 17 and 22 October, brought one of them in. 2.5.1 only updated a dependency and has the same bug;
  • you build for Android in release: flutter build apk, flutter build appbundle or flutter run --release. Flutter turns R8 on for every release build, and the app bundle that you upload to Google Play has the bug too;
  • debug and profile builds of the same app work.

iOS and macOS use shared_preferences_foundation, and the other platforms have their own packages, so only Android is affected.

The fix: upgrade to shared_preferences_android 2.5.2

shared_preferences_android 2.5.2 came out on 22 October. It ships consumer rules for R8, which keep the Kotlin classes in every app that uses the plugin. Upgrade it in the app's directory:

Shell
flutter pub upgrade shared_preferences_android

If you pinned the version with workaround 1, remove that dependency on shared_preferences_android before the upgrade. If you added the six rules from workaround 2, you can leave them in android/app/proguard-rules.pro: they do no harm. Then check that flutter pub deps | grep shared_preferences_android prints 2.5.2, and start the release build again with flutter run --release.

Workaround 1: keep shared_preferences_android below 2.5.0

Shell
flutter pub add 'shared_preferences_android:>=2.4.28 <2.5.0'

The app then depends on the package's Android side directly, and pub goes back to 2.4.28, which talks to Kotlin through a method channel as before. The rest of the app stays as it is.

To move to 2.5.2 later, remove the dependency and upgrade the package. Without the upgrade, pubspec.lock keeps 2.4.28:

Shell
flutter pub remove shared_preferences_android
flutter pub upgrade shared_preferences_android

Workaround 2: keep the Kotlin classes with R8 rules

To stay on 2.5.0 or 2.5.1, tell R8 to keep the classes. Put these lines into android/app/proguard-rules.pro, and create the file if the app has none:

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 { *; }

Flutter's Gradle plugin adds this file to the release build when it exists, so build.gradle.kts stays as it is. The rules come from Step 5 of Pigeon's native interop guide. Pigeon is the tool that generates the plugin's code.

After either workaround, start the release build again with flutter run --release.

Why the shared_preferences release build crash happens

Version 2.5.0 moved the plugin from method channels to Pigeon's native interop (flutter/packages#12329). The Dart code now calls the plugin's Kotlin code through JNI, and JNI finds classes and methods at run time by their names and descriptors.

R8 renames the classes that, as far as it can see, nothing refers to by name. The plugin's generated Kotlin classes have had @Keep since flutter/packages#13151, so SharedPreferencesAsyncApiRegistrar keeps its name. Its methods are suspend functions, though, and their last parameter is a kotlin.coroutines.Continuation. Nothing keeps that class. From a release build's build/app/outputs/mapping/release/mapping.txt:

Text
kotlin.coroutines.Continuation -> o1.d:

R8 renames the class and rewrites the getAll descriptor with the new name. The Dart side still asks for a method that ends with Lkotlin/coroutines/Continuation;, and that method no longer exists. The same goes for kotlin.Unit, kotlin.Result and the coroutine classes that package:jni 1.1.0 looks up by name in lib/src/kotlin.dart. The plugin has no consumer rules for R8, and the jni rules keep only its own package, com.github.dart_lang.jni.**.

Debug and profile builds run without R8, so every name stays and the calls work.

Why a green CI with debug builds missed it

The release APK builds without an error and fails only when its code runs. I found it by chance on the day 2.5.0 came out: while checking an unrelated change in SMF, I started a release build on an emulator, and it stayed on the splash screen. An app from a plain flutter create did the same. SMF's CI builds its generated apps for Android and starts them on an emulator, on every pull request and every night, and every Android build there was a debug build. So it stayed green.

Your users get a release build, so start one before they do: once a day in CI, or by hand before each release. Build it with flutter build apk --release, install it on an emulator and check that the first screen shows. R8 runs only in release builds, and that is the only place where a bug like this one shows up.

The upstream fix

  • flutter/flutter#194649 is the issue I opened on 17 October, with the steps to reproduce. Within a day, other apps linked to it from their own fixes.
  • flutter/packages#13311 is my pull request. It adds the six rules to shared_preferences_android as consumer rules, which R8 applies in every app that uses the plugin. It was merged on 21 October and came out in 2.5.2 a day later, since an outage of Flutter's CI stopped the first release run.
  • dart-lang/native#3732 is about shipping the rules in jni itself, so that every plugin on Pigeon's native interop gets them.

If another plugin in your app moves to Pigeon's native interop and its release build fails with a NoSuchMethodError or a ClassNotFoundException that names a kotlin class, try the same rules first.

How SMF keeps generated apps off 2.5.0 and 2.5.1

I ran into this while building SMF, a free, open-source Flutter project generator. From version 0.4.2, released on 17 October, its shared_preferences module kept shared_preferences_android below 2.5.0 in every app it generated. Since SMF 0.7, released on 27 October, it asks for 2.5.2 or later instead. The guide for coding agents in the app says why, and asks them to start a release build on Android before they change the constraint. SMF's CI now also starts a release build of a generated app on an Android emulator.

On iOS, only the archive failed for me: in apps with Swift Package Manager, FlutterFire's Crashlytics build phase breaks flutter build ipa while flutter run works. An earlier post has the fix for the flutterfire upload-crashlytics-symbols error. Google Sign-In can also fail only in Android release builds, when the resource shrinker removes its web client ID: see how to fix Google Sign-In errors in Flutter.

Back to all articles

Release notes by email

Get an email when SMF or its modules have a new release.

We use Resend. You can unsubscribe at any time.