Cannot overwrite backed up app data/ Want to exclude my app data from being backed up

Happens on Android 9 and 11
some of the npm packages that might be related
@capacitor/android”: “^2.4.6”,
@capacitor/cli”: “^2.4.6”,
@capacitor/core”: “^2.4.6”,

I’ve noticed that when installing from google play I have an issue with app data persisting via google’s auto backup.

Steps to reproduce:
be sure the app data has been backed up
clear data/cache (optional)
uninstall app
install app from playstore (either produciton or internal testing)

before the app is even run, I execute adb backup to get the /data/data/ dir

The reason this is causing issues for me is due to cookies being persisted in app_webview
The old saved cookie gets pushed up on an api call, then overwritten if it’s stale but the ovewrite/cookie update fails. I feel like overwrite/update fail could be a permission/access control issue.

If I clear the data/cache and restart the app it works fine.

Some other notes, if I change what API server i’m pointing at, thus changing the domain/host_key the app will also work fine. Same goes for changing the key/name of the cookie. This makes sense since those two params affect if it’s either inserted a new entry into the sqlite db or trying to update an existing one.

auto backup => Back up user data with Auto Backup  |  Android Developers

I would like to know if it’s possible to exclude my app in general from googles app backup or why I am unable to overwrite the data.

I’m about to see if It’s possible to clear the webview cache with a capacitor plugin, if cache includes the cookies then this should work but it feels like kind of a bandaid.

Update

I think I answered my own question on disabling backup from the above article

<application android:allowBackup="true" ... >        ...    </application>

I need to test this but it seems promising.

The last thing I want to try and figure out is why my app couldn’t overwrite the value. If I were to guess it may have to do with my app’s hostname not being localhost

or perhaps missing a permission?

Update

I’m unable to reproduce the error after disabling/deleting backup and enabling backup again.

I made sure a cookie got saved in backup and I’m seeing it in the adb backup, but now the app is having no issues overwriting it.