3

I have done many reinstalls of my OS on my Android phone in the last few months for various reasons. Every time, the biggest hassle is manually searching, downloading and installing all the apps I had in my previous installation.

I use a degoogled custom rom, downloading apps from F-Droid and Aurora Store, so no Google solutions are acceptable.

What I want, is to have a way to keep on my computer a copy of all the apks of the installed apps of my phone, and have it automatically updated too, so that when the time comes to reformat my phone and install everything all over, I will be able to simply adb install all of the apks in no time, instead of doing it all manually and waiting for them to also be downloaded. Any suggestions for how I can make that happen with existing programs, preferably open source?

Noob Doob
  • 225
  • 3
  • 8
  • 1
    If you know abd you can simply create a full backup of all non-system apps: adb backup -f all -all -apk -nosystem. Then unpack using the created backup via Android backup Extractor (abe), get the APK files and delete the other file(s). – Robert Jan 18 '21 at 16:40
  • 1
    as you mentioned custom rom, Migrate is the first choice for free backup solution. Titanium Backup has option for scheduled backup – alecxs Jan 18 '21 at 17:57
  • @Robert This only backs up a few of the installed apps. – Noob Doob Jan 19 '21 at 02:33
  • @alecxs This seems interesting. Is it open source by chance? – Noob Doob Jan 19 '21 at 13:47
  • nope, but ask the author in telegram group – alecxs Jan 19 '21 at 13:58

1 Answers1

6

If it's just the APK files, you could use the getapk script provided in the tools/ directory of my little helper Adebar, calling it e.g. with getapk user to retrieve all user-installed apps. You won't be interested in system apps, but for completeness:

$ getapk

getapk Extracting APK files from a connected device. getapk lets you extract a single app's APK, or that of all user apps, all system apps, or all apps altogether – depending on what parameter you passed it.

Syntax: /mnt/av/src/git/adebar/tools/getapk <package_name> | user | system | all

This requires ADB being available on your computer. Should you not have that yet, you might wish to take a look at Is there a minimal installation of ADB? here at our site. You don't write what OS you are on; getapk is a Bash script (as Adebar is a Bash tool), so it works best on Linux, was reported working fine on MAcOS, and also in Cygwin.

To have that automated, you could create a cron job (Linux/Mac; no idea how that works on Windows but AFAIK there's something like a "Scheduler" you could probably use). APKs will be named <packageName>.apk (e.g. org.fdroid.fdroid.apk) once retrieved, so always retrieving them to the same directory (i.e. calling the script while inside that directory) should take care that you have always the latest versions in there and no more. Though it wouldn't delete APKs of apps you've uninstalled later ;)

Izzy
  • 91,166
  • 73
  • 343
  • 943
  • Nice that you already have a complete script for that. I noticed that the script was last changed 2 years ago. Is your script already capable of saving split APKs (where each app consists of multiple APK files on the device)? – Robert Jan 19 '21 at 08:30
  • Seems to work for most apps installed. But for many I get a failed to stat remote object error. Searching around I found it might be possible to overcome it with root, but I'd rather not root because Magisk was the cause for many of the last rom reinstalls. Do you have a solution for that? Tried on Linux Mint 20. – Noob Doob Jan 19 '21 at 13:55
  • Further details, tried this on Pocophone F1, LineageOS 17.1. Examples of apps where this happened are Youtube and Shazam. – Noob Doob Jan 19 '21 at 14:31
  • 1
    @Robert feel free to build on it. I happily accept pull requests with improvements. And no, I haven't tried it with split APKs – hints are welcome, too. I guess the failed to stat could be such cases. The current logic is rather a "simple approach" which definitely can be improved… – Izzy Jan 19 '21 at 15:22
  • 1
    @NoobDoob I don't have Shazam, and the YT app is pulled fine from the test device having it. But I just fixed the mv: cannot stat 'base.apk' error. Will see if I can reproduce (and fix) the other one. Oh: you did call it with the user parameter, not all – you just want to backup user apps, not those the ROM ships with, right? The full error message reads: failed to stat remote object '{path}': Permission denied and in my test was only on some system apps. I'd yet need to find a split APK to test that. Edit: found one, indeed same error (just without the "permission denied"). – Izzy Jan 19 '21 at 15:40
  • 1
    OK, there you go – grab the update which now handles split-apks as well! They will be placed into a subdir using tha packageName and keeping the original names for the APKs, so should the dev decide to change their names or numbers, you might need to "clean up" manually yourself (e.g. deleting files older than X). – Izzy Jan 19 '21 at 16:33
  • All works now. Now it would be nice to have a script install them too, handling split apk's too, for the reinstall phase. I'd be happy to make one and PR to your project if you don't have time to put on it. My main problem is solved with this nonetheless. – Noob Doob Jan 19 '21 at 17:27
  • Would you have a problem with pasting the entirety of your script's code in your answer for the completeness of this thread? – Noob Doob Jan 19 '21 at 17:38
  • 1
    @NoobDoob "have a script install them too" => on its way: https://codeberg.org/izzy/Adebar/pulls/53 – and copy-pasting the entire script would quite blow up the answer. It's open-source and can be viewed in its repo. – Izzy Jan 20 '21 at 18:39
  • @Izzy I am the one who did the pull request, I did not mention it because I thought you realized it! I did not have time to work on it today, tomorrow I will most likely finish it. – Noob Doob Jan 20 '21 at 22:06
  • I assumed as much but wasn't sure. The note might be helpful for others, too – and I might include some facts from the comments with an update to the answer later, before cleaning up. Thanks again – and yes, at your convenience, no need to hurry ;) – Izzy Jan 20 '21 at 23:24
  • 1
    getapk still works a treat in 2023 on a fully updated Android 13 device without root. – dragon788 Mar 23 '23 at 15:59