-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempt to invoke interface method 'boolean android.content.SharedPreferences.contains(java.lang.String)' #380
Comments
I encountered a similar error. What I did was disabling backup in my AndroidManifest.xml: <application
...
android:allowBackup="false"
android:fullBackupContent="false"> |
Hi everyone! I've been having this issue as well. As @tahitiangabriel say, it's mentioned in #332 but also in #53. This last one is the most similar to my error, as the people updating the app are getting this error that leaves the APP totally broken. It seems that 5.0.2 is not resolving these issues as it appears that there are people reopening and commenting on these issues. In my case, not everybody gets the error, it's like 50/50, don't know if it may be linked to SO versions, iOS, Android or what... I will try to add a button to "Clear cache" or automatically deleteKeys on error to see if it works but definitely is not the best option... Let's see if we find a solution soon 😢 @dustincatap Could you explain your solution and why should work? Don't know why backup could be causing trouble in here. Thanks! |
version 5.0.2 still error when build app release mode |
You are getting
Initialization failed does not seem to be the same case that we are exposing here. Are you sure that you've reloaded properly your app after installing the library? |
i happen when i build to physical device in Release mode |
+1 |
I am also facing similar issue, issue: flutter PlatformException(Exception encountered, write, java.lang.NullPointerException: Attempt to invoke interface method 'android.content.SharedPreferences$Editor android.content.SharedPreferences.edit()' on a null object reference |
Any further update on this issue? |
I had this same error appear to me in a very specific scenario. I hope this report will bring some light in the issue. My app was working fine during development until I tried to uninstall and install it again to be sure that everything was going to work properly. Then the error occurred. I was using the --release flag on build. It seems to only happen on Android 11 (tried on two Xiaomi Mi 10T and on Samsung A31) on my code. I tried to reproduce this scenario on other Android versions (6, 9 and 12) but everything is running smoothly, even after reinstalling the app. Firebase Crashlytics reports the error happening when I call .containsKey or .read when trying to read previously stored user data to determine whether to show Login Page or the main route. |
@juliansteenbakker can someone please take a closer look at this? This is affecting a ton of users and really hard to debug. |
I downgraded to |
I have the same problem. Occurs continuously in release mode. |
I solved this problem. If your versions upper 5.0.0 & it was build to release mode, try to this code.
|
I've tried #380 (comment) and also an update to @mogol For now this is blocker for our app :( |
@mogol Same thing. This issue is completely preventing users from using the app. Could share some thoughts on what the issue could be ? It clearly has to do with getting the app's context. |
One of my users unblocked himself by Force stopping the app then clearing data & cache. Didn't work for others but I have no way of knowing if they proceeded correctly or if this is really what unlocked that one user. So it seems forcing a deletion solves the problem. Any way of doing this reliably @mogol ? |
I will check once more. But my previous attempts to reproduce and fix reliably were not very successful. So no promises 🤷♂️ |
I have put resetOnError to true on all accesses, and the error still occurs. |
Alright, seem I'm getting contacted at least once a day by a user with this issue, I'm going to have to drop this package. @mogol Please put a warning for the use of EncryptedSharedPreferences with this package. It is not stable and such a warning would have saved me a whole lot of trouble. |
I solved this problem with static AndroidOptions _getAndroidOptions() => const AndroidOptions( |
Any update in that topic? We are having few crashes on the daily basis. The error message looks similar:
We are using encryptedSharedPreferences option enabled. |
Any update? |
Our crash analysis tool shows us, that this situation mostly occurs on Android 6, especially on Huawei P8 Lite device. Maybe that will help? |
Hello, any update? I'm still getting this error. How to reproduce:
|
I think this is related to this https://developer.apple.com/forums/thread/36442 and https://stackoverflow.com/questions/4747404/delete-keychain-items-when-an-app-is-uninstalled |
We are having this issue on the Android platform only - it's not related to iOS. As far as I know, the Android removes the data from the encrypted preferences once app is uninstalled. |
Not sure. What if the manifest has |
I'm wondering, do using both |
@jeff-odopass That's a great question. We had the same combination in our app... Do you have some additional info as to why you suspect that that combination could cause problems? |
same here, for write, read and delete
Flutter 2.10.5 |
The root issue is for some reason the shared preferences instance fails to create but the error is swallowed and ignored. We need to forward the error to dart so we can catch it and see what’s happening. |
This really works but I don't know how. The interesting thing I have to mention is: this happens somehow randomly on a development device I used to test for year without any issue and then, once day it appears :D. No upgrade OS, nothing. Weird. UPDATED: I got it again on the same device after a while. Not update anything. |
Any update on this? I am facing the same thing one Android 13… |
We also experience this behaviour when installing our app from Play Store, uninstall it and then install from Firebase App Tester. App start does not even get to splash screen but stays just white. |
This might have something to do with isolates, referenced here and calling
|
Same issue here, the stacktrace is the following: Plugin version is 6.1.0.
|
Any updates? Getting this error using flutter oauth2 package. |
Hi there, I am facing the same issues with android 11 devices. |
Same issue here. |
I feel like this happened to me too.. flutter: 3.3.10 Not sure if this is helpful information: I'm accessing the plugin before the the void main() async {
WidgetsFlutterBinding.ensureInitialized();
DartPluginRegistrant.ensureInitialized();
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.manual,
overlays: [
SystemUiOverlay.bottom,
SystemUiOverlay.top,
],
);
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
var XxxxRepository = new XxxxRepository();
await Future.wait([
XxxxRepositry.init(),
]);
runApp(App());
}
|
We encountered the issue every time on a specific Samsung phone. During the investigation, I found that the Android code has baaaad behavior if it fails to create the encrypted preferences. No fallback is used then and that caused the NullPointerExceptions. I created a PR to fix the issue: For us, the fallback works as expected now. If any of you need it right now you can use: dependency_overrides:
flutter_secure_storage:
git:
url: https://github.com/jonasbark/flutter_secure_storage.git
path: flutter_secure_storage |
@mogol I am re-iterating my advice from this comment on putting a warning on this package about the use of EncryptedSharedPreferences. This package is widely known and lots of devs will start using it only to later run into this bug. Putting up a warning about this specific use case could save a lot of people (literally all of us in this thread) from having bad problems with their app. I have personally switched from this to using flutter_keychain, which has a much simpler implementation (though only stores string, but that's not really a problem) and I have encountered 0 problems with it so far. |
We are facing and similar issue where application is not working when we generate build using appbundle but works when we generate build using apk. Any solution? we are stucked and waiting for the solution. tried to apply @jonasbark solution but did not help Thanks |
I'm still facing the same issue on release mode with flutter_secure_storage: ^7.0.1, with the latest flutter version. |
I'm not sure this fix has been published yet by @juliansteenbakker. @MatyasK can you try using the master branch? |
@techouse master branch was last updated over 2 years ago... are you sure this is the right solution? |
@MatyasK my bad, the origin/develop branch. |
I just released v8.0.0 |
how to resolve issue ? |
Still encountering this issue on Android 11 devices with v8.0.0 |
@komaxx how often do you get the same problem with this version V8.0.0 ? is it only on android 11 ? or other else? |
@DavidIjsud |
got it, currently i am migrating to the last version and i hope , it does not crash frecuently. |
|
PlatformException(Exception encountered, read, java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.content.SharedPreferences.contains(java.lang.String)' on a null object reference at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin$b.run(SourceFile:24) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:246) at android.os.HandlerThread.run(HandlerThread.java:67) , null)
This issue was supposed to be fixed with #332 , but is still hapenning in 5.0.2
Only Android devices are affected by this issue.
The text was updated successfully, but these errors were encountered: