Android: How do I avoid losing data during reinstallation?
Recently, all of my Android project in Eclipse had errors trying to build the apps. Trying to fix the errors, I upgraded my Android SDK to 12.0. I finally figured out my problem was my debug certificate had expired. I deleted the certificate and cleaned all my projects. They now compile, but when I try to run them on my phone, I get the following messages:
[2011-08-16 08:01:39 - VIGMDB] WARNING: Application does not specify an API level requirement!
[2011-08-16 08:01:开发者_StackOverflow中文版39 - VIGMDB] Device API version is 8 (Android 2.2.1)
[2011-08-16 08:01:39 - VIGMDB] Uploading VIGMDB.apk onto device '0A3A94F17130E'
[2011-08-16 08:01:40 - VIGMDB] Installing VIGMDB.apk...
[2011-08-16 08:01:41 - VIGMDB] Re-installation failed due to different application signatures.
[2011-08-16 08:01:41 - VIGMDB] You must perform a full uninstall of the application. WARNING: This will remove the application data!
[2011-08-16 08:01:41 - VIGMDB] Please execute 'adb uninstall com.vig.vigmdb' in a shell.
[2011-08-16 08:01:41 - VIGMDB] Launch canceled!
I have data on my phone in these apps that I can't recreate and I don't want to lose it. My questions are:
How do i keep my data? Hindsight is 20/20. I now have code to copy my database to my SD card using my app, but I didn't know I couldn't access my database without it. I tried using ADB to pull the database, but I get a permission denied.
or
How do I make my application signatures the same again so I don't have to full uninstall?
You need to root your phone and then copy /data/data/com.your.apk.package
to sdcard. Then unisntall your app, install new vesrion of .apk and copy data back.
There is no supported way to install .apk which is signed by different certificate, while keeping the data from the older .apk.
Here is list of commands to copy your data to sdcard:
> adb shell
> su
> cp -r /data/data/com.you.apk.package/ /mnt/sdcard/backup
run "adb uninstall -k com.vig.vigmdb"
adb uninstall [-k] - remove this app package from the device ('-k' means keep the data and cache directories
Expired certificate is lost forever and can't be used (reborn) to sign new apps.
And without this signature you won't be able to access internal memory data (that hasn't been created as world readable or writable), since that's the heart of the android security model (to access those data you'd need either to run in the same process / same apk, or to share the same linux UserId, which can't be done if you don't share the same signature).
精彩评论