Comments (17)
Yep, I think you're right. My sharedPrefs was weird as well. I solved this by adding
<application
...
android:allowBackup="false"
android:fullBackupContent="false">
on AndroidManifest.xml.
So it can stop restoring stuff.
from flutter_secure_storage.
If you need fullBackupContent="yes"
, you can disable backup of prefs used by the plugin.
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<exclude domain="sharedpref" path="FlutterSecureStorage"/>
</full-backup-content>
from flutter_secure_storage.
Sorry it's unclear to me. Why would I need to set both android:allowBackup="false"
and android:fullBackupContent="false"
?
According to the Android doc, the latter is used to configure which data should be include/exclude when allowBackup
is enabled, right?
So, if I understand correctly, there are 2 viable solutions:
Option 1: Disable backup completely:
<application
...
android:allowBackup="false">
Option 2: Keep backup enable but exclude the shared pref used by this plugin:
<application
...
android:allowBackup="true"
android:fullBackupContent="@xml/backup_rules">
and this file res/xml/backup_rules.xml
:
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<exclude domain="sharedpref" path="FlutterSecureStorage"/>
</full-backup-content>
Am I correct?
from flutter_secure_storage.
I had two users w/ this problem and I did both recommendations from above:
Future<String> getEmail() async {
String rtn;
try {
rtn = await flutterSecureStorage.read(key: storageUserEmailAddressKey);
} catch (e) {
//https://github.com/mogol/flutter_secure_storage/issues/43
flutterSecureStorage.deleteAll();
}
return rtn;
}
and this:
<application
...
android:allowBackup="true"
android:fullBackupContent="@xml/backup_rules">
and this file res/xml/backup_rules.xml:
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<exclude domain="sharedpref" path="FlutterSecureStorage"/>
</full-backup-content>
And the issue was resolved
from flutter_secure_storage.
<application
...
android:allowBackup="false"
android:fullBackupContent="false">
This worked for me.
However, a fresh install was needed to make it work.
from flutter_secure_storage.
When choosing to exclude the shared preferences file from backup (Option 2
of #43 (comment)), now there is an additional XML file which must? be defined, if the app targets Android 12 or higher: https://developer.android.com/guide/topics/data/autobackup#include-exclude-android-12
As the doc says for the Android 11 and lower way:
Important: These XML backup rules are also used for devices running Android 12 or higher unless your app targets Android 12 (API level 31) or higher. In that case, you must specify an additional set of XML backup rules to support the changes to backup restore that were introduced for devices running Android 12 or higher.
This means one more attribute for the <application>
tag in the manifest and one more XML file.
In AndroidManifest.xml:
<application
...
android:dataExtractionRules="@xml/data_extraction_rules">
Create res/xml/data_extraction_rules.xml
:
<?xml version="1.0" encoding="utf-8"?>
<data-extraction-rules>
<cloud-backup>
<include domain="sharedpref" path="."/>
<exclude domain="sharedpref" path="FlutterSecureStorage"/>
</cloud-backup>
</data-extraction-rules>
Not sure if the <include>
tag is needed, maybe the <exclude>
is enough. I grabbed it from the linked Android docs.
Currently Flutter 3.3.9
defines targetSdkVersion
as 31
, so the above may be required for new apps: https://github.com/flutter/flutter/blob/3.3.9/packages/flutter_tools/gradle/flutter.gradle#L39
Of course disabling backup by setting android:allowBackup="false"
is still a valid option. In that case the above shouldn't be done.
from flutter_secure_storage.
Well... I kind of got it working trying some weird things.
In the screen you can see where's my problem, maybe its yours too.
To solve I just called ".deleteAll();" (or _sotrage.deleteAll(); following the example provided by the autor).
I just call it at app's first run using a "SharedPreferences _firstRun" variable.
I think its something with the keys recovery...idk
Oh, I also tryed to solve it by configuring android:allowBackup and it did nothing...
UPDATE
I could fix my problem in two steps:
1: Add this to the manifest:
<application
...
android:allowBackup="false"
android:fullBackupContent="false">
2: Call .deleteAll(); in my code only once to clean everything.
After this everything got working again (no need for sharedPreffs stuff I mention above and no need to keep .deleteAll(); in the code).
from flutter_secure_storage.
You can also catch the error and erase the failing value.
from flutter_secure_storage.
For my app, it seems like once a user runs into this issue, they will not get out of it simply by the addition of the manifest changes. Trying to communicate with this random app user is also not easy to try to get them to uninstall and reinstall.
My question is: Can I catch this exception in Flutter-space and handle it more gracefully?
I saw a comment somewhere among the discussions here on Github that suggested catching the exception and then running deleteAll(). Would this work? I ask because I cannot reproduce this locally. I can only debug this by releasing a new version and then watching the error reporting service for a day or two waiting for results from the handful of users that have run into this error.
Something like:
try {
String accessToken = await storage.read(key: accessTokenKey);
// obviously there is more code here
} on PlatformException catch (exception) {
storage.deleteAll();
// report the error as a "handled" error for confirmation
}
from flutter_secure_storage.
Hi @KathLevi ,
is it fresh install/updates/restore? debug/release? from Play Store?
And what model?
from flutter_secure_storage.
Same thing here on Samsung Galaxy J7 Prime.
It happened when updated to:
"Version: G610MUBS4CSB4/G610MZTO4CSB1/G610MUBS4CSB1"
from flutter_secure_storage.
@mogol It is a fresh install, debug, not from the play store but from my local machine. My phones are a Samsung Galaxy S8 and a Samsung Galaxy S9.
from flutter_secure_storage.
I'm getting this error too - not sure if it's a issue between using release and debug builds on the same phone? (side-loaded not via playstore). It won't go away when I try and un-install and then re-install the App.
from flutter_secure_storage.
I think its something with the keys recovery...idk
It looks like Samsung devices restore SharedPreferences.
I am looking for a device to debug the issue.
from flutter_secure_storage.
I can confirm the same issue is being reported by a few of our clients.
from flutter_secure_storage.
For anyone ending up here:
buildTypes {
release {
shrinkResources false
minifyEnabled false
signingConfig signingConfigs.release
}
}
https://stackoverflow.com/a/67026552/7735112
Alternatively:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
<application
...
android:allowBackup="false"
...
</application>
</manifest>
https://stackoverflow.com/a/71268807/7735112
from flutter_secure_storage.
√] Flutter (Channel stable, 3.16.4, on Microsoft Windows [Version 10.0.22621.2861], locale pl-PL)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2019 16.11.19)
[√] Android Studio (version 2022.3)
[√] IntelliJ IDEA Community Edition (version 2022.3)
[√] VS Code (version 1.85.1)
[√] Connected device (4 available)
[√] Network resources
sitll got the same issue. read from FlutterSecureStorage returns true not a value.
from flutter_secure_storage.
Related Issues (20)
- Can run app with flutter_secure_storage HOT 1
- [WEB] Alternative to the experimental implementation using WebCrypto HOT 1
- Linux App Won't build HOT 2
- secure storage is deleted on app upgrade.
- Migrate to package:web
- When is new version coming with isCupertinoProtectedDataAvailable() etc HOT 3
- Update flutter_secure_storage_web depends on js ^0.6.3 HOT 5
- During archive process for ios the following exception occurs
- [iOS] Are there any plans to add Privacy Manifests? HOT 4
- [macOS] Read always return null with signed and notarized app HOT 7
- Android App Build Fails After Installing flutter_secure_storage HOT 1
- [Web] Error: TypeError: 86400: type 'int' is not a subtype of type 'Iterable<dynamic>' HOT 1
- FlutterSecureStorage on macos build macOS (darwin) fails HOT 3
- Flutter Secure Storage is Not working on Release Mode in Android 14 HOT 1
- [iOS] Native app update HOT 2
- App uses CBC with PKCS5/PKCS7 padding HOT 3
- [WEB] Upgrade of js Dependency in flutter_secure_storage_web HOT 1
- Implementing encryption with the same logic as FlutterSecureStorage HOT 2
- Is this project still maintained? HOT 11
- I suspect a bug where my session keys are deleted and it causes my session to be logged out. HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_secure_storage.