How to migrate app data when switching the app source Say I have "FunnyApp" installed from Playstore, now it turns up at F-Droid – and I want to replace the Playstore version by the F-Droid one (same issue vice-versa). Trouble is, I cannot simply update the app from the new source as the signature doesn't match (F-Droid signs with their own key). FunnyApp doesn't offer any "export" functionality, but I don't want to lose its data.

What would be possible approaches to perform a proper switch?

Traps:


Simply updating/installing from "the other source" does not work (signature mismatch)
performing a data-only adb backup doesn't help, as the restore will fail for the same reason


I have some vague ideas on root-based solutions which I haven't tried yet (e.g. Titanium Backup might be able to restore data despite of the changed signature, and there's also some XPosed module (InstallerOpts?) offering to "suppress the signature warning"). But before "messing up big" I thought to ask here if someone might already have successfully tried some solution.

Non-root solutions preferred (so more people can profit from), root-based solutions acceptable, XPosed as requirement OK as well.



Some reasons why one might want to "switch sources" (aka "cross-update"): Getting rid of proprietary dependencies, app no longer updated at original source …
Rootless

Sorry but AFAIK it's not possible :( I've never seen any app/tool/utility successfully modifying other apps' data, not even reading!
Alternatively you could do that in a custom recovery, but who uses a custom recovery without rooting? So read below.

Simple Root (Manual way)

Don't take it too hard. Just move its original data away, uninstall the original app and install the new one, then move the data back and chown. Sample shell commands are below.

# mv /data/data/com.example.foo /data/media
 * UNINSTALL_ORIGINAL_APP
 * INSTALL_NEW_APP
# ls -ld /data/data/com.example.foo
 * take note of the user (e.g. u0_a123)
# mv /data/media/com.example.foo /data/data
# chown -R 10123.10123 /data/data/com.example.foo


Explanations for each step:


Move original app data to an alternative place. Because Androis automatically delete irrelevant files in certain directories, we need a safe place as the Alt. AFAIK unknown files are ignored in /data/media so that is chosen.
Replace app. No explanation.
Obtain the UID of newly installed app. Wrong UID will make Package Installer delete app data.
Move data back and change UID.


A small note: The builtin chown command does not accept option -R (recursive) by default in Android L or lower. You need BusyBox in that case. In Android M and up it just works fine.

Root Utilities


Titanium Backup

With TiBu you can easily back up existing data, then safely remove the old app and install the new app. Then as long as both packages have the same package name, you can restore the data for the app with TiBu, intact!

However, this solution is essentially a data-backup, so it will not be maintained here. If you want to learn more about backing up &amp; restoring data, check out our tag wiki for backup, under the App-based backups section.


Xposed Modules (Easiest, Recommended by iBug)

XInstaller and its successor, InstallerOpt, can hook Package Installer to allow packages with mismatching signatures to be installed (by skipping sig check). Then all your data is preserved and you can easily switch to different versions. This is the method I am currently using and it has been working fine. Sad that Xposed isn't officially available for Android N (so far), so this solution is only for Android M and down.

Theoretically, they should not cause anything wrong because all they do is hooking the signature checking function and change its return value to a truthy value, bypassing the check. If the replacement package have any other defects than mismatching signature, the installation will still fail, so no faulty packages can be installed even if you skip signature check.


  Important Notice
  It is not recommended to leave that option (skip sig check) enabled all the time. Leaving it enabled will create a big security flaw as hacked apps (almost always use a different signature) can also be installed. I personally enable it only when needed and disable it as soon as I finished my package replacement.