react-native-async-storage / async-storage

An asynchronous, persistent, key-value storage system for React Native.
https://react-native-async-storage.github.io/async-storage/
MIT License
4.68k stars 467 forks source link

Storage items persist after uninstall on Android device #569

Closed mdbiscan closed 3 years ago

mdbiscan commented 3 years ago

Current behavior

I'm using AsyncStorage for persisted storage. I noticed (while debugging an unrelated issue with Expo SecureStore) that the key/value pairs are persisting after I've uninstalled the app from my device.

I've tried the following:

It is my understanding that uninstalling the app should also remove persisted storage. However, this issue goes beyond this assumption if I am incorrect.

The items always show up after I uninstall and reinstall the app. Reloading the app does not have this same issue. I read through some old/closed issues here that showed others having this problem, with solutions that have not worked for me. Even after using AsyncStorage.clear() or AsyncStorage.removeItem(), the items will appear on every new install, but only after the app has been uninstalled from the device.

Expected behavior

After new installation or removing them, the storage items should no longer exist on the device.

Repro steps

  1. Remove storage items with AsyncStorage.clear() or AsyncStorage.removeItem()
  2. Delete app storage and cache in Android Settings -> Apps & Notifications
  3. Uninstall the app from the device
  4. Stop react-native
  5. Run ./gradlew clean in the android directory
  6. Start react-native with --reset-cache flag
  7. Run react-native run-android to install the app

Environment

krizzu commented 3 years ago

Hey @mdbiscan , thanks for filling in all the details!

One thing that comes to my mind is Auto back up of user data, that's enabled by default for devices targeting Android API 23+. You mention that you search through old issue, so I guess you tried to disable it? (dunno if you have access to manifest file in Expo app)

Is your project ejected? Are you able to reproduce this on non-expo app (react-native init)? Could it be that some of the other dependencies doing the backup or maybe Expo is doing backups? cc @brentvatne

mdbiscan commented 3 years ago

@Krizzu thanks for the reply!

The project is ejected. I hadn't thought of Auto Backup. I read about automatic exclusion to iCloud for iOS devices, but didn't see one for Android. I will look into it.

mdbiscan commented 3 years ago

Looks like this setting in the AndroidManifest.xml file is on by default: android:allowBackup="true"

For future reference, this is the generated XML line from Expo:

  <application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="true" android:theme="@style/AppTheme">

Setting this to false solves the issue. I'm not sure this is a good idea or not, as we also use keychain storage. I'm not sure if this backup feature also saves encrypted storage to the cloud.

Either way, thanks for pointing me in the right direction. I figured it might be some obtuse setting.

Zhou-Bill commented 3 years ago

ios has the same problem, how to solve in ios?

krizzu commented 3 years ago

Did you try to disable iCloud backup? documentation

Noitidart commented 2 years ago

Hey @mdbiscan and @krizzu, does this apply to the Documents Directory pointed to by FileSystem.documentsDirectory? On iOS and Android?

I think I'm having some bugs due to this its just a hunch. I'm going to try to set that allowBackup to false in xml for Android, how could I do this for iOS?

Not using AsyncStorage but Expo filesystem - https://docs.expo.dev/versions/latest/sdk/filesystem/

bryanltobing commented 11 months ago

https://github.com/react-native-async-storage/async-storage/issues/569#issuecomment-808319211

i tried this in my current my project, and a repro project

both have android:allowBackup="true"

but only in my current project that the async storage data persist upon app uninstall and reinstall

in my repro project which is new expo project, data will be removed after i reinstall the app.

still not sure how to fix this

yushanwebdev commented 3 months ago

@mdbiscan, you saved my day

dytra commented 6 days ago

yup, that's likely the issue! Since android:allowBackup="true" is enabled, Android is backing up the app's data to the cloud, and when the user reinstalls the app, the old data is restored automatically.

If some users already have old data backed up to the cloud, they will continue to restore that data even after you disable backup for new users. To fully resolve the issue, users need to manually clear their app backup data.

Steps for users to clear backup data:

Go to Settings > Google > Backup > App data. Find your app in the list and select it. Tap Delete backup.