Xamarin Android losing keystore after each deploy in emulator - xamarin

I'm discovering Xamarin Android with Visual Studio and I'm working with the keystore.
All my code is based on Xamarin's https://github.com/xamarin/Xamarin.Auth
When I deploy and use the keystore, everything is working fine. Data are persisted and I can save, delete and retrieve them without a problem.
I can turn off the emulator or kill the application, the keystore is still here with the data in it.
But if I modify the code and redeploy the application without stopping the emulator, my keystore is lost.
Any idea on where I should start digging to troubleshoot this problem. I don't have any exception.

Looks like you need to set the setting to Preserve application data/cache on device between deploys.
Check this answer for details:
SharedPreferences not saving values properly

Related

How to upload to Apple's My Apps from a Xamarin project

I specifically need help getting the app build into my apps. I am so new to the MAC ecosystem. I need to get my app build from my windows 10 box (parallels) running VS2017/Xamarin Forms project uploaded to My Apps. What i have found is helpful if you are using xcode on the mac.
I have read tons of pages and help files and with all of that what I have includes:
created an app in VS2017/Xamarin that runs happily on the emulator from the MAC (MacBook Pro)
purchased the app dev subcription from apple
created a Production certificate (I don't need this yet but I was in there so...)
created a Development certificate
created a key pair from the Dev cert (that show up in the keychain)
created an App Group
created my app's placeholder under My Apps on App Store Connect
added my iPhone to devices via connecting to the Mac getting the UDID from iTunes
created a development provisioning profile for my iPhone (Not sure how this helps my testflight plight)
Assumptions
You must submit for review the same way for both TestFlight and Prod release to the actual store.
You don't need to open the app in xcode outside Xamarin
There is a tool or concept I am missing out on.
For development outside of Xcode, you will want to use Apple's Application Loader App to upload your app to App Store Connect.
As I said in comment to Matt below his correct answer to my actual question above, I needed to get the project right to get to that point.
Here are the more intimate details for the lurkers. I hope this helps some of you.
I was getting, or trying, to get all of this in place manually instead of letting VS do it's work getting this stuff together while I got to coding. FastLane FTW
Open the account management window, go to Tools > Options > Xamarin > Apple Accounts
Add your AppleID
Click on your appleID
Click the add button
Select your id in the lower text area
then add your distro cert. As is proper you deploy to TestFlight as a prod release.
Then get over to to your iOS project properties:
Make sure that your project is outputting an IPA. (Not Beer ;) )
These are my settings that worked. There could be other configurations that work as well.
I never get the automatic provisioning to work. And while this bundle signing settings look like it will not work, it does. I have received my apple approval for beta and users are in testflight.
Also, make sure you update the version of the app in the plist for subsequent releases. This change is not carried through from the AssemblyInfo.cs as one might expect. viola.
If you see this during debug make sure your debug version has Developer (Automatic) set for your debug settings.
FWIW - My VS2017:
While this does not perfectly match the info # https://learn.microsoft.com/en-us/xamarin/cross-platform/macios/apple-account-management?tabs=windows it worked for me. That page was key to the solution and deserves citing. Your mileage may vary.
If I missed something please reach out and I will update this.

Where to save app info to survive reinstallation after building?

I currently use App.Current.Properties dictionary to save some basic data needed for the app to connect to a database.
Unfortunately, when building and reinstalling the app on the Android simulator (didn't tried on the iOS one), app data seems to be wiped, so every time I test the app I've to re-enter connection info.
How can I avoid that?
Does it work if you start the app without redeploying it? If you just click the app icon on the emulator. If it does not you have propbarly forgot to call the save method.
Application.Current.SavePropertiesAsync();

application-settings not working as expected

Wrote a small app and saved a string via application-settings module.
I can read the value fine within that same session.
If I close the app in the emulator and restart it in the emulator, I can read the value also.
But if I rebuild the project in the IDE (VS Code - pressing "refresh/reload" icon) - the app restarts and the stored value is no longer there.
Seriously?
Is application-settings stored data not persistent across sessions.
If you rebuild your application, it will delete the old application on your smartphones + all the datas that was stored in application settings.
If you don't want that the stored datas disappear meanwhile you are changing the code you should use the livesync options.
In order to do that, go with a terminal at the root of your app projet and type the following command :
tns livesync ios --watch
For IOS or
tns livesync android --watch
For Android
I hope this will help you

Xamarin.Forms application properties not saved between sessions with Android

In my cross-platform app I save application properties in the following way:
Application.Current.Properties["myValue"] = "Test";
await Application.Current.SavePropertiesAsync();
I then retrieve them later like this:
string myVal = Application.Current.Properties["myValue"];
This works perfectly when using the Android emulator. I can close the emulator down, and when I restart it again, my app data is preserved.
However, when I deploy this app to a physical Android device, data preservation works as expected until I close the app and open it again. At this point I retrieve an empty value. It's as though the data is only saved to memory (and not to file).
Furthermore, the iOS version of the exact same app works faultlessly. When I open the app up, all previous values have been saved and I can retrieve them.
What am I doing wrong on the Android version? Is there an Android setting, permission, or option which I need to enable to have the values saved between app sessions when actually deployed to a phone?
I had a similar problem where only the debug version saved Properties. I think we're still waiting for the bug fix, and this is the workaround on Xamarin Forms bugzilla.
In short: go to .Droid project settings -> Android Options -> Linker
and enter/add "System.Runtime.Serialization" to Skip linking assemblies.
Wow! After lots of research, I have getting solution for same issue in mine. Problem is that, when i store List or DataTable in Application.Current.Properties then all properties are removed after reopen app but if i store List or DataTable as serialize, it working fine.
In VS you need to enable the option:
Preserve application data/cache on device between deploys
You can find this at Tools > Options > Xamarin > Android Settings.
I don't know if this has stopped in the latest updates of Xamarin Forms, the data is available until the application is running similar to session but persistent storage does not work.
The best api I think available for this is Akavache https://github.com/akavache/Akavache.
You can read this blog https://codemilltech.com/akavache-is-aka-awesome/.
Update
There is a bug filed in bugzilla:
https://bugzilla.xamarin.com/show_bug.cgi?id=26444
I don't remember exactly which part of this solved the issue, but when I followed the instructions to prepare the Android application for release from start to finish, the issue went away. The problem occurred when debug builds were used on an Android device.
https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_1_-_preparing_an_application_for_release/
The link details the suggested settings for the Android project when releasing to device. Following these instructions should solve the issue.

(Xamarin) WinPhone app won't start

I'm working on a project using Xamarin to build an app for WinPhone and Android.
On the Android device, it works fine.
When I try to run the app on the WinPhone device, the app starts opening and then it closes. On the console I see "TaskHost.exe has exited with code 0."
I don't see any error.
A guy that was working on it before, was using the WinPhone device without problems.
When I started working on it, the only thing I needed to change was the SQLite.WP80 version. He was using 3.8.7.1 and my VS only provided 3.8.8.1.
Has anyone faced a similar problem?
Or how can I see what is wrong? In the console output there is no errors.
I've added a breakpoint in the begining of WinPhone, but it doesnt't arrive there.
Thanks in advance!
Have you changed your namespace? Check if the startup object in the project setup is set accordingly.
Finally I found the problem.
By returning the code revision, I found one where the WinPhone project was working on phone.
Then, I started looking for differences.
Someone renamed AppWP.xaml to AppWinPhone.xaml.
Then, on project properties > startup object, it was blank.
I just set the object back and it worked.
(Why not an error message saying what is wrong...)
Thanks!

Resources