Emulator "Disconnects" on Starting App

Hello! I’ve been having issues with the Android emulator (specifically while working with Flutter), and I wanted to see if anyone else has experienced/solved similar difficulties.

I recently ran ‘flutter create .’ in the terminal to generate the iOS files I’ll eventually need before publishing my app. For some reason, some time afterward the Android emulator stopped working.

I can only get the emulator itself to function after hard restarting it once, and afterward, I run ‘flutter run’ in the terminal to get my app onto the emulator. Whenever I open it, however, I see the standard plain white loading screen, and then the emulator says “Disconnected” at the top.
There are no relevant errors, and the only Output is this:

2024-08-05T02:20:48Z [android] Lost connection to device.
2024-08-05T02:20:49Z [android] ✘ Preview shutdown unexpectedly

Has anyone seen this issue before? Any thoughts or recommendations on how to proceed (so far I’m just trying standard troubleshooting)?
Thanks!

Have you tried to reset the workspace?
I get an error similar to that sometimes, the emulator local:5555 will bork out.
Resetting the workspace seems to be the easiest way to get running again.

After resetting and reloading the project give idx a minute or two to fire up the new emulators.

@Alex - may be related to some of the Android failures you had been investigating.

I have unfortunately - it does get the emulator to start but somehow as soon as I open the app it does the same thing and I’m back to square one :sweat_smile:. Thanks for the suggestion though! I’ll probably look into my code and see if there’s something causing the app to malfunction at runtime.

1 Like

Update: The issue was that I ran ‘flutter create .’ after working on the project for some time (adding dependencies, files, etc.). Deleting the project (after saving all of my code) and creating a new one fixed this, as I could run ‘flutter create .’ from the start to generate the iOS files, then add my code back in.

Weird fix, but it worked for now at least.

It seems like port 5555 is flaky. Next time when this happens, can you try adb connect localhost:5555 please? Additionally if this alone doesn’t do it, can you restart the adb server with adb kill-server && adb start-server before running the connect command please?

This should solve the emulator disconnected problems without having to reset the workspace. Please let me know if this doesn’t work.

2 Likes

This works to start the emulator back up, but my Flutter app isn’t listed in the device’s App Libary, forcing me to run flutter run again. Once the app is built to the emulator, it automatically tries to open it but immediately exits again, and shuts down the emulator temporarily. Interestingly, this issue doesn’t exist on the web server - is it possible that the Android SDK needs to be upgraded? I haven’t been able to find an SDK manager within IDX to do so.