Giter VIP home page Giter VIP logo

Comments (17)

MilloshFey avatar MilloshFey commented on June 1, 2024 76

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.

mogol avatar mogol commented on June 1, 2024 57

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.

ncuillery avatar ncuillery commented on June 1, 2024 48

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.

bartonhammond avatar bartonhammond commented on June 1, 2024 15

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.

cirediew avatar cirediew commented on June 1, 2024 10
<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.

slaci avatar slaci commented on June 1, 2024 8

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.

MilloshFey avatar MilloshFey commented on June 1, 2024 7

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...

error

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.

szotp avatar szotp commented on June 1, 2024 3

You can also catch the error and erase the failing value.

from flutter_secure_storage.

eimermusic avatar eimermusic commented on June 1, 2024 2

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.

mogol avatar mogol commented on June 1, 2024

Hi @KathLevi ,
is it fresh install/updates/restore? debug/release? from Play Store?
And what model?

from flutter_secure_storage.

MilloshFey avatar MilloshFey commented on June 1, 2024

Same thing here on Samsung Galaxy J7 Prime.
It happened when updated to:
"Version: G610MUBS4CSB4/G610MZTO4CSB1/G610MUBS4CSB1"

from flutter_secure_storage.

KathLevi avatar KathLevi commented on June 1, 2024

@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.

alsocalledchris avatar alsocalledchris commented on June 1, 2024

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.

mogol avatar mogol commented on June 1, 2024

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.

VernonGrant avatar VernonGrant commented on June 1, 2024

I can confirm the same issue is being reported by a few of our clients.

from flutter_secure_storage.

cpuell avatar cpuell commented on June 1, 2024

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.

jacekwitkowski avatar jacekwitkowski commented on June 1, 2024

√] 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.