18
votes

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.

18
Same! Which flutter version are you using? I'm using 1.5.4-hotfix.2. - Jches
flutter_barcode_scan caused the error for me. Does anybody know a working barcode-package? - relascope
I just did a cold boot and it worked. - Tayyab Mazhar
I am facing the same issue, can it be related to the firewall i have on my Zorin OS(Ubuntu based) - Daniyal Ahmad
Try wiping emulator data - Muhammad Faizan

18 Answers

18
votes

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.

5
votes

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

3
votes

Sorry I don't know how you can solve it on Windows but for Mac Os users: Go to System Preferences -> Network -> Click on your Phone -> Uncheck "Disable unless needed" Uncheck Disable unless needed

Thanks to https://github.com/flutter/flutter/issues/46698#issuecomment-565643127

2
votes

For my case, I met the error when I used 3rd parties such as facebook_login, twitter_login incorrectly.

To check:

  • comment the libs from pubspec.yaml, corresponding code as well.

To fix:

  • update correctly config for the 3rd parties.

Hope this help.

1
votes

Try

flutter run --release

I faced the same issue after upgrading flutter 1.13 but the above command helped.

1
votes

Uninstall app in Emulator fixed same issue for me

1
votes

For me it was caused by flutter_facebook_login plugin causing issue i removed it and i could afford to remove facebook login option but in your case you can try different version of flutter_facebook_login or you can use different plugin for loggin in using facebook.

1
votes

In virtual device manager, try one of these options.

Wipe Data
Cold Boot Now

enter image description here

0
votes

It seems it can be different things. In my case, I removed a package I was using, barcode_scan.

0
votes

I have the same problem and I go to xcode -> window -> device & simulator, under Installed Apps I remove some apps and it works.

0
votes

Open the project in android studio => Start your Emulator - OR - Connect your android device with Debug mode "on" => Run the Project on android studio => Run your project from VS code or from command line using flutter run

0
votes

When I deleted the emulator in AVD Manager and rebuilt it, it worked.

0
votes

For me, it was caused by phone screen saver. Emulator screen was locked. After I pressed on power icon, the screen opened. then I run it again and everything is working.

0
votes

I have resolved this problem after add some code in android folder.

1.Add below code in AndroidManifest.xml

 <meta-data android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id"/>

    <activity android:name="com.facebook.FacebookActivity"
        android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name" />
    <activity
        android:name="com.facebook.CustomTabActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="@string/fb_login_protocol_scheme" />
        </intent-filter>
    </activity>

2.Add your Facebook app id in strings.xml

<string name="facebook_app_id">380000000000000</string>
<string name="fb_login_protocol_scheme">fb380000000000000</string>

3.Add dependencies in pubspec.yaml

flutter_facebook_login: ^1.1.1

Pub get and run.

0
votes

In my case, I just closed the simulator, and ran it again.

0
votes

I was having the same error message. In my case, the problem was just a configuration that I changed in Runner.xcodeproj.

Open runner.xcodeproj in Xcode, go to the General tab -> App Icons and Lauch Images -> "Launch Screen File". I had changed it to Main and that cause the error, changing back to "LaunchScreen" option solved the problem for me.

0
votes

Try

flutter doctor -v

I had faced same issue. So I run flutter doctor -v command.

Then I found the error

✗ Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses.

flutter doctor --android-licenses this command resolved my issue.

0
votes

This happened to me too, the problem was I was using a vpn in my PC, I turned the vpn off, and everything just worked fine