flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.81k stars 27.65k forks source link

Better error message for not connecting to Android debug device - WIFI debugging #154545

Open FMorschel opened 3 months ago

FMorschel commented 3 months ago

Steps to reproduce

  1. Connect a physical Android device to debug
  2. Leave it there unattended for some time until it shows on flutter doctor -v that it is offline (maybe only happens on wifi debugging?)
  3. Try to debug a project with flutter run -v
  4. See the output below (logs).

About point two here, not sure this is exactly when you can see this output. Look https://github.com/Dart-Code/Dart-Code/issues/5245 for more info. It happens to me whenever I have left my phone lock the screen by itself and have not used it for some time. If I lock it manually or recently this does not happen.

Expected results

Device is offline message. Or some better message handling when not in verbose mode.

Actual results

Connection closed before full header was received message only in verbose mode.

Code sample

Not important.

Screenshots or Video

Not important.

Logs

Logs ```console [ +1 ms] Latest build already installed. [ ] executing: C:\Users\felip_0vh5fa6\AppData\Local\Android\sdk\platform-tools\adb.exe -s 192.168.200.50:42307 shell -x logcat -v time -t 1 [ +355 ms] --------- beginning of system 09-02 17:13:23.818 I/wpa_supplicant( 1637): Heartbeat 62 [ +13 ms] executing: C:\Users\felip_0vh5fa6\AppData\Local\Android\sdk\platform-tools\adb.exe -s 192.168.200.50:42307 shell am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x20000000 --ez enable-dart-profiling true --ez enable-checked-mode true --ez verify-entry-points true br.inf.sunsoft.produtores/br.inf.sunsoft.produtores.MainActivity [ +157 ms] Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x20000000 cmp=br.inf.sunsoft.produtores/.MainActivity (has extras) } [ ] Waiting for VM Service port to be available... [+1327 ms] VM Service URL on device: http://127.0.0.1:45599/PSAwNkkAsUk=/ [ +1 ms] executing: C:\Users\felip_0vh5fa6\AppData\Local\Android\sdk\platform-tools\adb.exe -s 192.168.200.50:42307 forward tcp:0 tcp:45599 [ +61 ms] 50529 [ +1 ms] Forwarded host port 50529 to device port 45599 for VM Service [ +3 ms] Caching compiled dill [ +78 ms] Connecting to service protocol: http://127.0.0.1:50529/PSAwNkkAsUk=/ [+31591 ms] Fail to connect to service protocol: http://127.0.0.1:50529/PSAwNkkAsUk=/: HttpException: Connection closed before full header was received, uri = http://127.0.0.1:50529/PSAwNkkAsUk=/ws [ +2 ms] Error connecting to the service protocol: failed to connect to http://127.0.0.1:50529/PSAwNkkAsUk=/ [ +21 ms] "flutter run" took 66.603ms. [ +176 ms] #0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3) #1 RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:874:9) #2 FlutterCommand.run. (package:flutter_tools/src/runner/flutter_command.dart:1408:27) #3 AppContext.run. (package:flutter_tools/src/base/context.dart:153:19) #4 CommandRunner.runCommand (package:args/command_runner.dart:212:13) #5 FlutterCommandRunner.runCommand. (package:flutter_tools/src/runner/flutter_command_runner.dart:420:9) #6 AppContext.run. (package:flutter_tools/src/base/context.dart:153:19) #7 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:364:5) #8 run.. (package:flutter_tools/runner.dart:130:9) #9 AppContext.run. (package:flutter_tools/src/base/context.dart:153:19) #10 main (package:flutter_tools/executable.dart:93:3) [ +46 ms] I/flutter (16413): Drift: Sent SELECT * FROM sqlite_master; with args [] [ +2 ms] I/flutter (16413): Drift: Sent select 1 with args [] [ +211 ms] ensureAnalyticsSent: 253ms [ +1 ms] Running 2 shutdown hooks [ +5 ms] Shutdown hooks complete [ +26 ms] exiting with code 2 ```

Flutter Doctor output

Doctor output ```console [√] Flutter (Channel stable, 3.24.1, on Microsoft Windows [Version 10.0.22631.4037], locale pt-BR) • Flutter version 3.24.1 on channel stable at C:\Users\felip_0vh5fa6\.puro\envs\stable\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 5874a72aa4 (2 weeks ago), 2024-08-20 16:46:00 -0500 • Engine revision c9b9d5780d • Dart version 3.5.1 • DevTools version 2.37.2 [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at C:\Users\felip_0vh5fa6\AppData\Local\Android\sdk • Platform android-34, build-tools 34.0.0 • Java binary at: C:\Users\felip_0vh5fa6\AppData\Local\Programs\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.10.6) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.10.35201.131 • Windows 10 SDK version 10.0.22621.0 [√] Android Studio (version 2024.1) • Android Studio at C:\Users\felip_0vh5fa6\AppData\Local\Programs\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314) [√] VS Code (version 1.92.2) • VS Code at C:\Users\felip_0vh5fa6\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.92.0 [√] VS Code (version 1.88.0-insider) • VS Code at C:\Users\felip_0vh5fa6\AppData\Local\Programs\Microsoft VS Code Insiders • Flutter extension version 3.64.0 [√] Connected device (4 available) • SM G780F (mobile) • 192.168.200.50:41835 • android-arm64 • Android 13 (API 33) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22631.4037] • Chrome (web) • chrome • web-javascript • Google Chrome 128.0.6613.114 • Edge (web) • edge • web-javascript • Microsoft Edge 128.0.2739.42 ! Device 192.168.200.50:39975 is offline. [√] Network resources • All expected network resources are available. • No issues found! ```
danagbemava-nc commented 3 months ago

Hi @FMorschel, curious, what device are you using? And is that the only device you're seeing this on? I have been trying to get my pixel 7 to read as offline, but after the phone locks for several times, it is still able to connect

FMorschel commented 3 months ago

I've used a Samsung Galaxy S23U and had this experience but currently downgraded to see the behaviour on older devices and am using a Samsung Galaxy S20 FE. Not sure if this is only a Samsung thing. As I said on the issue for Dart-Code, it seems weird that the phone receives the app and installs it just fine bit is not able to connect to the service protocol.

As I said, it is pretty inconsistent as well. I'm not really sure how to make this happen. The one thing I noticed is that I connect it through wifi debugging and leave the phone locked for some time while doing other things (not deving or deving without debugging) and whenever I come back, I always need to manually unlock my phone to make debugging work.

danagbemava-nc commented 3 months ago

I'm guessing this might be because adb might be dying on us. Possibly related https://github.com/flutter/flutter/issues/9707

Labeling this as a proposal for an improved message.