Bug 27266 - Preserve data/cache not respected
Summary: Preserve data/cache not respected
Status: REOPENED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler (show other bugs)
Version: 5.1
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Ben Beckley
URL:
Depends on:
Blocks:
 
Reported: 2015-02-20 14:41 UTC by Eshaan
Modified: 2017-08-09 01:48 UTC (History)
5 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Eshaan 2015-02-20 14:41:43 UTC
I have preserve data/cache checked in the settings but whenever I do a debug build onto my android device it always uninstalls the old apk and reinstalls the new one.
Comment 1 Jonathan Pryor 2015-02-20 14:59:53 UTC
The Preserve data/cache option has nothing to do with whether the .apk is uninstalled or not.

The Preserve data/cache option controls whether the .apk is uninstalled with `adb uninstall -k` or not:

>    ('-k' means keep the data and cache directories)

The .apk contains all Android resources, assets, and Java code. If any of these changes for any reason -- e.g. resources are added or changed, or a C# class was altered to override a new Java method -- then the .apk MUST be rebuilt and redeployed. There is no way to avoid it.
Comment 2 Eshaan 2015-02-20 15:54:26 UTC
so there's no way to change it to just install with -r? It seems like my data is getting wiped every time I deploy a build.
Comment 3 Eshaan 2015-02-26 15:59:29 UTC
also this would be better because when you force an uninstall/install any widgets/home screen shortcuts that had been set are removed. If you guys need proof that my data is getting removed when i push builds I can send a video or something.
Comment 4 Ben Beckley 2015-02-27 16:42:34 UTC
Ran some manual tests and found that "preserve data/cache between application deploys" was working as expected.

Used monodroid-samples/Notepad on Debug mode and followed the steps below:

Part 1:
install app that preserves data/cache
go to "preferences > projects > android > tun on preserve data/cache…"
clean and rebuild app
deploy app and store some data

Part 2:
go to "preferences > projects > android > turn on preserve data/cache…”
clean and rebuild
redeploy app with preserve data/cache on via XS
observe that data should be preserved
stop debugging

Part 3:
go to "preferences > projects > android > tun off preserve data/cache…”
clean and rebuild
redeploy app with preserve data/cache off via XS
observe that data is gone

Link to sample:
https://github.com/xamarin/monodroid-samples/tree/master/NotePad

Development environment:
https://gist.github.com/BenBeckley/8ff21dc7d96021fb6a6c
Comment 5 Eshaan 2015-03-05 21:03:10 UTC
Try this on the google n6 with latest lollipop - it seems to only happen on this device.
Comment 6 Ben Beckley 2015-03-06 12:44:03 UTC
Followed the same steps as listed in Comment 4 with a Nexus 6 (5.0.1) and could not reproduce the issue. Everything worked as expected.
Comment 7 Eshaan 2015-03-06 13:30:14 UTC
I will try with the notepad sample app and get back to you.
Comment 8 Eshaan 2015-03-06 14:13:54 UTC
I reproduced the bug. 

1. Install notepad app -> make a note.
2. make some changes to the xml in the notepad app (I added <Button android:layout_width="4dp"
        android:layout_height="4dp"
        android:text="hello"/> 
in node_edit.xml)
3. push the app with xamarin
4. The note you previously created will be gone (on nexus 6 lollipop).

if you then push builds without making changes it does preserve data. but if you make changes it doesn't.
Comment 9 Eshaan 2015-03-06 14:16:22 UTC
Also ensure that xamarin says "removing previous version of the application" when you are pushing - as I believe this is where the data gets removed.
Comment 10 Ben Beckley 2015-03-09 11:38:13 UTC
Followed the steps in Comment 8 with a Nexus 6 (5.0.1) and was unable to reproduce the bug with preserve data/cache checked. Also ensured that it was "removing previous version of the application" as per the suggestion in Comment 9.

Could you please give details on your Xamarin Studio setup? Go to the tab option "About Xamarin Studio > Show Details" and then provide the information. It will look like this:
https://gist.github.com/BenBeckley/8ff21dc7d96021fb6a6c
Comment 11 Eshaan 2015-03-09 14:38:21 UTC
Hmm maybe it's just something wrong with the phone.. like because it's rooted or something. Let me try adb uninstall/reinstall with -k and see if that works. here is my xamarin setup.

http://pastebin.com/CgtKz53a
Comment 12 Jonathan Pryor 2017-02-14 01:24:03 UTC
> so there's no way to change it to just install with -r? 

Long delay, I realize... At the time, I tried to figure out why we didn't use `adb install -r`, and couldn't find an answer.

Now, I might: `adb install -r` is unreliable, at least for me:

https://github.com/xamarin/xamarin-android/commit/c37d2195e8514df3d08a39703258cf8016da3347

If `adb install -r PACKAGE` doesn't actually make the updated package usable on the device, it's *broken*, and that's what I and a co-worker had to debug through for *hours* last week...
Comment 13 dpedrinha 2017-08-09 01:48:39 UTC
Different app, different device, app data is always wiped, including SharedPreferences and GoogleApiClient data. Need to login every time.

Please fix it. We two are not the only one complaining about it.

Note You need to log in before you can comment on or make changes to this bug.