Open moehajj opened 2 years ago
fwiw, the callback succeeds without any exception if I add SharedPreferences.setMockInitialValues({});
before the final prefs = await SharedPreferences.getInstance();
. But that doesn't help as that's only intended to be used in testing.
fwiw, the callback succeeds without any exception if I add
SharedPreferences.setMockInitialValues({});
before thefinal prefs = await SharedPreferences.getInstance();
. But that doesn't help as that's only intended to be used in testing.
This sounds similar to another issue I saw earlier in a project.
Other plugins like flutter_secure_storage
work, right?
We may have a behavior in the shared prefs plug-in..
Yes, the plugin flutter_secure_storage
works fine! I'm also using sqflite and local_notifications and they work fine. It's just SharedPreferences
.
Any ideas why some plugins work and others don't?
Yes, the plugin
flutter_secure_storage
works fine! I'm also using sqflite and local_notifications and they work fine. It's justSharedPreferences
.Any ideas why some plugins work and others don't?
No idea yet & I can only offer guesses at this moment. It may have to do with the queuing process inside the Shared Pref plugin, but this does not explain why the plugin is not responding.
You are most invited to fire up the debugger for the Android side and do some digging... :)
Not sure if this is related, but this started to happen to me after updating my emulator to Android 12.
Does it also happen on a android 11 device or emulator?
Ah, false alarm. I tested this on android 11 and 9 emulators, and I'm getting the same problem there.
When I updated my emulator to android 12 a while ago I jumped onto the prerelease of this library, suspect that's when this exception started happening, just that it took me a while to realize.
Related:
https://github.com/fluttercommunity/flutter_workmanager/issues/149 https://stackoverflow.com/questions/71115025/flutter-cant-initialize-shared-preferences-with-workmanager (same problem in iOS) http://47.57.228.104/flutter/flutter/issues/93523
I've tried a lot of things but nothing worked.
Below workaround from https://github.com/flutter/flutter/issues/98473#issuecomment-1041895729 fixes the issue
Thanks for filing this; I've filed #98591 for the general problem (which we weren't aware of when updating the plugins).
While we investigate whether we can adjust Flutter to handle this automatically in the future, here's a workaround that should allow using the current versions of the plugins:
- Add dependencies on
shared_preferences_android
andshared_preferences_ios
.- At the beginning of your background isolate entry point, add something like:
if (Platform.isAndroid) SharedPreferencesAndroid.registerWith(); if (Platform.isIOS) SharedPreferencesIOS.registerWith();
This worked for me, thank you sooo much
UPDATE: This workaround https://github.com/flutter/flutter/issues/98473#issuecomment-1041895729 resolves the issue however it does not work with obfuscation. Enabling workmanager debug shows notification but actual task is not run:
After 10 minutes shows another notification for the same task, but again actual task is not run. Note it was a one time task. Looks like workmanager keeps on trying to run the job every 10 minutes which fails hence keeps on trying to run it forever.
Note it works fine in release mode without obfuscation.
Log:
2022-02-18 19:35:43.146 17527-20502/? E/flutter: [ERROR:flutter/shell/common/shell.cc(93)] Dart Unhandled Exception: NoSuchMethodError: No top-level getter 'Mdd' declared. Receiver: top-level Tried calling: Mdd, stack trace: Warning: This VM has been configured to produce stack traces that violate the Dart standard.
pid: 17527, tid: 20502, name Unknown isolate_dso_base: 7d52cc8000, vm_dso_base: 7d52cc8000 isolate_instructions: 7d52f50d70, vm_instructions: 7d52f4c000
00 abs 0000007d52f57d1b virt 000000000028fd1b _kDartIsolateSnapshotInstructions+0x6fab
2022-02-18 19:35:43.146 17527-20502/? E/flutter: [ERROR:flutter/runtime/dart_isolate.cc(681)] Could not resolve main entrypoint function. 2022-02-18 19:35:43.146 17527-20502/? E/flutter: [ERROR:flutter/runtime/dart_isolate.cc(165)] Could not run the run main Dart entrypoint. 2022-02-18 19:35:43.148 17527-20502/? E/flutter: [ERROR:flutter/runtime/runtime_controller.cc(381)] Could not create root isolate. 2022-02-18 19:35:43.148 17527-20502/? E/flutter: [ERROR:flutter/shell/common/shell.cc(580)] Could not launch engine with configuration.
@ened can you look into above comment, or do you want me to create a new issue?
Any news or update? 😪
All of you, who are impacted, should give a thumbs up on this issue https://github.com/flutter/flutter/issues/98591 so that it gets prioritized, as MissingPluginException
issue is impacting all plugins which are moving to "in-package method channel", same issue is now happening with path_provider
(path_provider_android 2.0.12
to be specific)
Note, it's not going to solve the obfuscation issue, which is a separate issue.
flutter/flutter#98475
Ive created the Awesome Notification's plugin, and im trying to do the same as you: Create a parallel flutter engine to run dart code while the app is terminated.
What I'm coming to the conclusion that on iOS, the plugins are not getting register on the beginning, as the same on Android.
Currently, im trying to do it calling the method GeneratedPluginRegistrant.register(with: flutterEngine!)
, but im not getting visibility inside the background class, as your BackgroundWorker.swift
.
I created a issue thread in flutter to discuss possible solutions to this. https://github.com/flutter/flutter/issues/99883
Same problem here, with shared_preferences
.
The workaround doesn't work on Linux, so Linux solutions are appreciated.
Version
Describe the error I get the exception
MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)
when trying to use the SharedPreferences plugin inside the callback method. I have only tried to get this to work on Android.To reproduce, conveniently you can use the example application, I've tried getting it to work and it fails the same way.
Just run the app, click
Start the Flutter background service
->Register OneOff Task
. You will see that the callback fails, with the following output:I added a
try-catch
statement here to see the error, as such:Output:
You can see the
I/flutter ( 8608): MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)
.Output of
flutter doctor -v