Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to uninstall android apk without losing data?

Is there a way to use adb uninstall on the apk, but make the data persist? I've lost the original key to my app, and now I would like to update it, but without losing the previous data. So I need to uninstall it first to add the new apk with the new key. Is this possible?

I forgot to mention I'm executing commands via a .bat file.

like image 339
Comic Sans MS Lover Avatar asked Oct 05 '12 15:10

Comic Sans MS Lover


2 Answers

EDIT: Should have specified, the following will work only for Android 4.0 and above.

Just enable adb access, and use this command:

adb backup -noapk -f /backup/myAppBackup.ab com.yourapp.packagename

You should then have a file stored in your root directory (on Windows, your C:\ or equivalent) in a folder called backup.

Once you have this file, assuming the package name stays the same, you should be able to simply use the command

adb restore /backup/myAppBackup.ab

to restore the data.

Now, I don't know for certain that this will work once you've changed the key, but I'm fairly certain it relies only on the package name, so the signature key shouldn't matter. More info here.

like image 86
Kevin Coppock Avatar answered Sep 21 '22 19:09

Kevin Coppock


Batch-friendly version.

My-make-clean.bat:
adb pull /data/data/com.blah.bla/file1 file1
adb pull /data/data/com.blah.bla/file2 file2
adb pull /data/data/com.blah.bla/file3 file3
...
adb uninstall com.blah.bla
adb install YourApkFile.apk
like image 27
Shark Avatar answered Sep 23 '22 19:09

Shark