Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Emulator Error Connecting to Service Protocol

I am having an Issue with Flutter in Android studio, where whenever I run my flutter app, it will print this error; "Error connecting to the service protocol: HttpException: Connection closed before full header was received, uri = http://127.0.0.1:53305/9So9Wn564F4=/ws" , and it will "disconnect" from the app in the emulator. The app will still run, but I can't use functions like Hot Reload.

I am on a Windows machine, and Flutter Doctor does not indicate any errors. I have tried to read up on similar issues on github posts, but I have been unable to resolve the problem.

Do any of you guys have any ideas on how to solve this issue?

The problem does not occur when running on an actual device, only in the emulator.

like image 234
Simon Olsen Avatar asked May 11 '19 18:05

Simon Olsen


3 Answers

If you return to a previous version of android, (Android Pie), you will no longer have this problem, it is related only to the latest versions of android (Q, 29), in others you will no longer have the problem.

like image 108
Luan Martins Gepfrie Avatar answered Nov 20 '22 10:11

Luan Martins Gepfrie


A quick restart of the phone worked for me

like image 18
William Avatar answered Nov 20 '22 10:11

William


What exactly happened

Hey I went into the same problem too. I cannot use a Emulator inside windows because my pc is a very low end pc. So, I had to use my phone instead. It is a Samsung Galaxy J2 Pro (SM-J210F) with Android 6.0.1 (Android Marshmallow). I used that phone to develop flutter apps regularly, but suddenly, I went to this problem.

Here's what happened when I tried to run "Flutter Attach" in VS-Code(v1.52.0).

command

flutter attach --machine -d 420054e7960eb400

exception

StateError: Bad state: Existing VM service clients prevent DDS from taking control.

#0      DartDevelopmentService.startDartDevelopmentService (package:flutter_tools/src/base/dds.dart:83:11)
<asynchronous suspension>
#1      FlutterDevice.connect.<anonymous closure> (package:flutter_tools/src/resident_runner.dart:249:11)
<asynchronous suspension>

Fixing the issue (In Windows 10)

So, I ran these commands to fix the issue.

Fixing the Flutter SDK

-flutter clean -v

-flutter channel stable ** (Optional if these didn't fix the issue)

-flutter upgrade -v

-flutter pub cache repair -v (Disclaimer: It will download each and every version of all the packages. Be sure to have really fast internet or give at least an hour to this.)

Configure your Proxy/VPN

If you are using a Proxy or VPN to connect to the internet,
Make sure that application isn't resolving localhost via that.(DNS)

Kill ADB and Dart processes.

After that, kill adb and dart process on Windows.
(I don't know exactly how to kill these in Mac/Linux. Sorry About That)
Run these commands in the Command Prompt.

taskkill /f /im dart*
taskkill /f /im adb* (You can run "adb kill-server" too)

Fixing the ADB in the Windows (*Optional).

Navigate to %HOMEDRIVE%:\Users%USERNAME%.android"
In my case, It is ( C:\Users\Isira Adithya.android )
Then delete adbkey.

Fixing the Android Debugging in the Android Device

Disconnect the device from the computer.
Go to Settings -> Developer Options,
Turn off USB Debugging and Turn it on again.
Revoke USB Debugging authorizations.
Restart the device.

Update Windows and Android System (If above didn't solve the problem)

Conclusion

I think these steps should fix your problem.
Also I am still 16 years old and I am not a very experienced developer.
If these didn't fix, use this to get more info. Github Issue

like image 8
Isira Adithya Avatar answered Nov 20 '22 10:11

Isira Adithya