[VS2019]Android Emulator hangs when debugging app

RobDevRobDev Member ✭✭

Further to my last question where VS2019 failed to deploy my Xamarin Forms app to the Android emulator due to 'lack of space', I increased the 'memory' in the emulator settings and tried again. This time the emulator just 'hung' during the deployment process.
I tried switching between VS2017 and VS2019 and found that when I try to debug my app for the first time from either VS2017 or VS2019 the emulator does a 'Cold Boot'. When it does a 'Cold Boot' my app is successfully deployed and run in the emulator. However, on all succeeding debug attempts with the same version of VS the emulator doesn't do a 'Cold Boot' but 'restores state' from, I presume, the previous session. After it does this the emulator just hangs. There is, apparently, no way to force the emulator to do a 'Cold Boot' each time it runs other than switching between VS2017 and VS2019. I also tried uninstalling the app from the emulator before finishing the debugging session but this made no difference to succeeding debug attempts - the emulator still just hung. This situation, for me at least, makes Xamarin development virtually unusable.

Is anyone else experiencing the same or similar problems.

Any help/advice would be gratefully received.

Best Answer

Answers

  • PatrickJelittoPatrickJelitto Member ✭✭✭

    In order to force a "cold boot" you can try the following steps:

    1- Tools
    2- google emulator manager

    select your device

    3- press Start
    4- flag "wipe user data"
    5- press Launch

  • RobDevRobDev Member ✭✭

    Hi PatrickJelito,

    many thanks for your reply. First off, my edition of VS2019 doesn't have a 'google emulator manager' in the Tools menu. It does have an 'Android Device Manager' option as shown in the following screenshot:

    The Android Device Manager displays each of the 'emulator' devices available to me, as in this screenshot (The entry highlighted shows the 'device' I've been using for testing):

    The only way I can alter the settings for the chosen device is to hit the 'Edit' button. This displays the edit page as shown below:

    However, there is no 'wipe user data' option available on this page nor is there, as far as I can see, any other option for forcing a 'Cold Boot' each time the emulator is run.

    I have asked around on the Microsoft MSDN forums about this but the only person who's responded has said that, as far as he has been able to determine, there's no way to force the emulator to do a 'Cold Boot' each time its run (other than switching between VS2019 and VS2017). This surely can't be the case can it?

    Kind regards,

    RobDev

  • JohnnyThJohnnyTh Member, Xamarin Team Xamurai

    RobDev, you may want to try the Factory Reset option in the Android Device Manager for your target device emulator. Make sure to shut down the emulator first. Then try right clicking the device in the manager and seeing if Factory Reset shows up. This will reset the device so be cautious when using it.

  • RobDevRobDev Member ✭✭

    Hi JohnnyTh,

    many thanks for your reply. I tried out your suggestion of doing a Factory Reset on the device and it seems to work but not quite as I expected.
    Firstly, I was a bit worried that doing a Factory Reset would set my altered memory settings back to their original values, however, the Factory Reset didn't touch the memory setting (Hooray!!).

    Anyway, the first time I tried running the app after the Factory Reset it worked. I then did another Factory Reset and ran the app again. This time it failed to run with the following error messages:

    "Error: Device could not find component named: com.companyname.AwesomeApp/md5ab0053feacd7b849e5347dd4e508b363.MainActivity
    The application could not be started. Ensure that the application has been installed to the target device and has a launchable activity (MainLauncher = true).
    Additionally, check Build->Configuration Manager to ensure this project is set to Deploy for this configuration.
    Couldn't connect debugger. You can see more details in Xamarin Diagnostic output and the full exception on logs"

    I then did another Factory Reset and ran the app again and it worked with no problems. I repeated this process a few times, just to get and idea of what's happening here, and it seems the error happens every other 'Factory Reset/Run' attempt. This is getting a bit beyond weird.

    At least now I don't have to switch between VS2017 and VS2019 anymore but I think the Android Emulator could really do with fixing. It does seem to me to be a bit flaky.

    Thanks, once again, for your help.

    Kind regards,

    RobDev

  • RobDevRobDev Member ✭✭

    Hi JohnnyTh,

    I tried your tip about leaving the emulator running and worked perfectly. I did a factory reset before the initial run but left the emulator running thereafter, as you suggested. Each time I ran the app from VS2019 it deployed and ran without problems. I was a bit worried that I might have to uninstall the app after each run but VS2019 deploys a new version each time so I didn't have to. Many thanks for your advice and suggestion. I can now do Xamarin development and testing without any of the grief I was getting before. I wish your advice have been incorporated into the official documentation, it would have saved me a lot of stress and frustration.

    I would love to know why, in my case, the emulator doesn't work properly without the factory reset though. I can't imagine anyone explaining that soon.

    Many thanks for all your help, once again.

    Kind regards,

    RobDev

  • JohnnyThJohnnyTh Member, Xamarin Team Xamurai

    RobDev, I'm glad that worked out well for you. Good luck on your projects!

Sign In or Register to comment.