flutter_secure_storage
flutter_secure_storage copied to clipboard
[Android] PlatformException when invoking write value
Hi, error occured in our release prod when we trying to write value into secure storage.
so far it only happened in Samsung J7+. Is there anyway to resolve this?
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError
PlatformException(Exception encountered, write, java.lang.NullPointerException: Attempt to invoke interface method 'byte[] wc.i.a(byte[])' on a null object reference at vc.a.m(Unknown Source:24) at vc.e$b.run(Unknown Source:267) at android.os.Handler.handleCallback(Handler.java:790) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:164) at android.os.HandlerThread.run(HandlerThread.java:65) , null). Error thrown null.
Flutter version: 2.10.5 flutter_secure_storage: 8.0.0 Android version: 8.1.0 Android model: Samsung J7+
PlatformException(Exception encountered, write, java.lang.NullPointerException: Attempt to invoke interface method 'byte[] e.d.a.f.k.a(byte[])' on a null object reference flutter_secure_storage: 7.0.0
Hi,
I have same problem.
PlatformException(Exception encountered, write, java.lang.NullPointerException: Attempt to invoke interface method 'byte[] com.it_nomads.fluttersecurestorage.ciphers.StorageCipher.encrypt(byte[])' on a null object reference at com.it_nomads.fluttersecurestorage.FlutterSecureStorage.write(FlutterSecureStorage.java:104) at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin$MethodRunner.run(FlutterSecureStoragePlugin.java:145) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:223) at android.os.HandlerThread.run(HandlerThread.java:67
Flutter version: 3.10.2 flutter_secure_storage: 8.0.0 Android version: 11 Android model: Android box
Hi, I encountered the same problem.
Occurs on Android version: 11 Flutter version: 3.7.3 flutter_secure_storage: ^7.0.1 Device: Imin D4
I've looked into this problem, and the culprit for the NPE is here:
https://github.com/mogol/flutter_secure_storage/blob/017ce8182b0be0feefef9083c72ab0de1eaf4571/flutter_secure_storage/android/src/main/java/com/it_nomads/fluttersecurestorage/FlutterSecureStorage.java#L148-L153
A try
/catch
that swallows any exception without handling it. storageCipher
remains unassigned after an unknown exception, which later results in the NullPointerException
.
Removing this catch
(i.e. letting the root cause be reported) got me to:
java.lang.Exception: No certificate found under alias: la.foton.brb.myphone.FlutterSecureStoragePluginKey
at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.getPublicKey()
…which appears to be the same as #58, an issue with no satisfactory answer.
It seems the best/only workaround without understanding the problem better and changing the plugin is to set AndroidOptions(resetOnError: true)
. This will erase all data on the device, but hopefully after that it will be able to initialize properly. (I can't reproduce this error on my devices, so I haven't had the opportunity to try this yet. Fortunately, it only affects a tiny number of users in our case)
Is there any plans to fix this issue? one of our user is currently facing this problem. is there any other alternatives to work around at the moment?
You can catch the exception and write a fallback handler. If the user's device doesn't work with Secure Storage, use another storage provider.
I am closing all older issues. If this issue still exists in the latest version, please let me know.