Reputation: 6406
I'm migrating an Android app written in Java to Xamarin.
The old app (Java) stores some data in the AccountManager and a SQLite DB and I'm looking to migrate that over to a new format when existing users install the new app (Xamarin) as an update so they won't loose their existing data
I'm looking to test the migration code, so I installed a version of the old app on a physical device and then I deployed the new version (a version higher) to the same device but each time I do that, Visual Studio removes the older app and before installing the new app which makes it impossible to debug the migration code (the AccountManager entry which contains data is nuked the moment the older version is uninstalled before launch).
Some things I did try before posting here:
I've enabled "Preserve data/cache between application deploys" (https://forums.xamarin.com/discussion/96902/android-app-keeps-getting-uninstalled)
Enabled Fast Deployment
Nothing seems to work - I just need the data preserved between deployments so my migration code has a chance to run.
I'm using Visual Studio 2017 for Mac if that's relevant
Upvotes: 10
Views: 1701
Reputation: 471
A solution for this could be using the Beta tool from Crashlytics, as follow answer: https://stackoverflow.com/a/46155893/4855062
Upvotes: 0
Reputation: 17755
I think there are two different things :
When deploying, Visual Studio never updates but uninstalls, then reinstalls the application. Jonathan Prior explained it in 2017 and it is still the case today. As far as I know there is no way to change that, but this is usually not a problem because you can choose to keep the data (VS uses then adb uninstall -k
).
On the other hand, if you build a release APK, and install it with adb install -r
, then you are using the exact same update mechanism that will be used to deploy your app on users devices. Your migration code will be executed, if not it just means that it doesn't work.
Upvotes: 4
Reputation: 1203
If all else fails, you can probably just publish a beta version to playstore and download it from there
What I think you can do is (though I never tried it myself) you can change the applicationId of one app, so both will be present in your phone at the same time. Then since the underlying file structure of both app should be same, you can copy the storage content of previous version to your current version
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.mynewversion"
minSdkVersion 19
targetSdkVersion 28
versionCode 2
versionName "1.0001"
}
Upvotes: 0