How to migrate app data when switching the app source


Question

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 …


Answer

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:




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

  2. Replace app. No explanation.

  3. Obtain the UID of newly installed app. Wrong UID will make Package Installer delete app data.

  4. 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 & restoring data, check out our tag wiki for , 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.



Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes