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
162.29k stars 26.66k forks source link

Android 14 - Flutter stuck at "Waiting for VM Service port to be available..." #144999

Open Anti049 opened 2 months ago

Anti049 commented 2 months ago

Steps to reproduce

  1. Create new flutter app in VS Code.
  2. Attempt to debug on physical Android 14 device.

Expected results

App should start and be debuggable.

Actual results

App never gets past starting splash screen, log stuck at "Waiting for VM Service port to be available..."

Code sample

Code sample ```dart import 'package:flutter/material.dart'; void main() { runApp(const MainApp()); } class MainApp extends StatelessWidget { const MainApp({super.key}); @override Widget build(BuildContext context) { return const MaterialApp( home: Scaffold( body: Center( child: Text('Hello World!'), ), ), ); } } ```

Screenshots or Video

Screenshot [Screenshot_20240312_110526](https://github.com/flutter/flutter/assets/7032588/f0865abe-4d01-4ece-9e10-e654fe68f26f)

Logs

Logs [Log File](https://pastes.io/w86vxonhit)

Flutter Doctor output

Doctor output ```console [✓] Flutter (Channel stable, 3.19.2, on Microsoft Windows [Version 10.0.22631.3155], locale en-US) • Flutter version 3.19.2 on channel stable at C:\Tech\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 7482962148 (2 weeks ago), 2024-02-27 16:51:22 -0500 • Engine revision 04817c99c9 • Dart version 3.3.0 • DevTools version 2.31.1 [✓] 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\1099996508.adm\AppData\Local\Android\sdk • Platform android-34-2, build-tools 34.0.0 • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874) • 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.8.2) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.8.34322.80 • Windows 10 SDK version 10.0.22000.0 [✓] Android Studio (version 2023.2) • Android Studio at C:\Program Files\Android\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.9+0--11185874) [✓] VS Code, 64-bit edition (version 1.87.0) • VS Code at C:\Program Files\Microsoft VS Code • Flutter extension version 3.84.0 [✓] Connected device (4 available) • NX769J (mobile) • FY23328102EA • android-arm64 • Android 14 (API 34) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22631.3155] • Chrome (web) • chrome • web-javascript • Google Chrome 121.0.6167.86 • Edge (web) • edge • web-javascript • Microsoft Edge 122.0.2365.80 [✓] Network resources • All expected network resources are available. • No issues found! ```
darshankawar commented 2 months ago
NX769J (mobile)   • FY23328102EA

@Anti049 What device is this ? Can you provide make and model ?

Also, could you confirm if this only happens when you use "Debug" (and not "Run"), or occurs with both options and also try capturing a log (please remove anything sensitive before sharing):

Run the Dart: Capture Debugging Logs command Reproduce the issue Click Cancel on the logging notification to stop logging and open the log Remove anything sensitive from the log Attach the log here, in a gist,

Anti049 commented 2 months ago

The device is a Nubia REDMAGIC 9 Pro.

Issue still occurs when running without the debugger, as seen here.

darshankawar commented 2 months ago

I am unable to replicate this on Android 14 device which isn't similar to the one mentioned above. Based on the report, I'll keep the issue open for team's input / attention. There's a similar issue open but it is for ios https://github.com/flutter/flutter/issues/129246

/cc @DanTup for thoughts.

DanTup commented 2 months ago

Issue still occurs when running without the debugger, as seen here.

Setting "dart.allowFlutterForcedDebugMode": false in your settings might fix this for Run (not Debug), at least temporarily. In order to support some functionality, we now default to attaching a debugger even in Run mode (which means a failure to attach a debugger affects both modes). That flag opts-out of this behaviour.

As for the original issue, this feels like something that came up in the past when the logcat output wasn't being captured correctly (for example in one case the VM Service URL was being censored by manufacturer tweaks and in another it only worked when called through a shell).

It may be useful to run adb logcat and capturing the output when trying to launch the app to see whether there's any useful output there (I don't think the log captured above includes everything). I believe the app should print something like "VM Service listening on " and Flutter would detect that.

Anti049 commented 2 months ago

Setting that setting to false in VS Code DOES allow me to run without debugging, but couldn't find anything like that in the logcat (found 3 lines relating to VM Service, but all just say either "sarting" or "success"). Please see the logcat output below.

Logcat Output

DanTup commented 2 months ago

@Anti049 was this log captured while you tried to launch in debug mode? Oddly, there is no mention of Dart or Flutter in the whole log. There are a few mentions of "VM Service" but it's not clear to me whether that's the Dart VM Service or an unrelated program ("D trustedui@1.0-1-service-qti: TrustedUI-VM service starting." - I don't know what TrustedUI is).

Out of interest, if you run from the terminal with flutter run, does it print a VM Service URL ("A Dart VM Service on Windows is available at") and can you hot reload with r?

Anti049 commented 2 months ago

I got this log by running adb shell -x logcat from the terminal and then running in debug mode from VS Code. Is there another way to capture the log you're looking for?

Running flutter run from the terminal directly launches the app on the device as it should, but the terminal is still stuck on "Waiting for VM Service port to be available...", and that's the only mention of VM Service in the whole output.

DanTup commented 2 months ago

Thanks, I suspect that would be the case (and confirms it's not specific to how VS Code is starting the app).

Running that same command here (on a Pixel 4a) does work as expected, in the output I can see:

03-14 14:47:25.127  9725  9785 I flutter : The Dart VM service is listening on http://127.0.0.1:39177/wQC1nUoLATg=/

It's possible that it not showing up in the logs is the cause of this problem - the flutter tool is scanning those logs to find the VM Service URL, but it's not finding it.

Unfortunately I don't know a lot about logcat/Android so this might need input from someone that knows more in this area. https://github.com/flutter/flutter/issues/82520 was caused by a manufacturer filtering out URLs in the logcat output - it's possible this is something similar (but maybe they're filtering the whole row instead of just replacing the URL with asterisks), but I had a quick search and wasn't able to find any other complaints of this nature.

Also - it's a long shot, but it may be worth looking through Debugging settings on the phone (presumably where you enabled USB Debugging) to see if there are any options that seem to be related to logs that might be filtering them.

Anti049 commented 2 months ago

No luck with the developer settings, unfortunately.

Sanotsu commented 1 month ago

When using flutter3.16.7, the same problem occurs even with an empty flutter project on Nubia Z50Ultra on Android 14, but runs fine on Android 13.

kannel-outis commented 3 weeks ago

I have a red magic 8 pro on android 14 and I face the same issue.

christopherfujino commented 3 weeks ago

FYI @reidbaker, this is something we should probably keep an eye on

SawyerGuo commented 3 weeks ago

I have the same issue

shynriu commented 2 weeks ago

Currently having the same issue

shynriu commented 2 weeks ago

Currently having the same issue

i want to add that I have a Redmagic 8S Pro (NX729J), and that this problem arrived just after i upgraded to Android 14, it was working fine on Android 13

jemsoftie commented 2 weeks ago

I have Android 12 and I have same issue and I just recently used java 21 as well as downgraded my flutter version

jemsoftie commented 2 weeks ago

I have Android 12 and I have same issue and I just recently used java 21 as well as downgraded my flutter version

I'm also looking for solutions but it looks like a recent problem

andrewkolos commented 1 week ago

@Jemina15 and @SawyerGuo, may I ask what device you are running into this issue with? I am curious whether this issue is only affecting Nubia devices.

SawyerGuo commented 1 week ago

@Jemina15 and @SawyerGuo, may I ask what device you are running into this issue with? I am curious whether this issue is only affecting Nubia devices.

yes, Nubia

jemsoftie commented 1 week ago

Nubia devices

I use Honor X6

andrewkolos commented 5 days ago

To summarize, I'm guessing the tool is getting stuck here

https://github.com/flutter/flutter/blob/80042124ad461548fcd518e7d41557d59cc5405b/packages/flutter_tools/lib/src/android/android_device.dart#L705-L711

which would mean the flutter tool never sees a line in the device log matching this pattern

https://github.com/flutter/flutter/blob/c9d4c749b54e7411f9a8f2fe6060e66383db734a/packages/flutter_tools/lib/src/globals.dart#L297

As @DanTup pointed out earlier, it's possible that either 1) this line is not appearing in the device logs at all; or 2) it is appearing, but its contents are being tampered with by the OS. To try to figure out which of these is the case, I'd like to see more examples of device logs after running flutter run (similar to what @Anti049 provided earlier).

andrewkolos commented 5 days ago

If anyone experiencing this issue would like to help, you can produce your own logs by following these steps:

  1. Run adb logcat -c to clear the log buffer
  2. Run adb logcat > out.txt to stream the device's log buffer to a file
  3. flutter run to start the app (or do so through VS Code)
  4. Once the app is running, copy the contents from out.txt into a GitHub gist (or some other text sharing tool) and provide a link to it in this issue thread. It would also be ideal if the device model, Android version, and output from flutter doctor -v is also provided.

For example, I did this with an emulator and got this from logcat. I see

05-13 12:17:22.260 15613 15696 I flutter : The Dart VM service is listening on http://127.0.0.1:35595/XOCg3_e_sG4=/

This is mainly happening on Nubia devices[^1], and I don't have a good understanding of how popular these devices are (and how critical it is to be able to debug Flutter apps on them). As a result, I do not consider this issue to be high enough priority for me to obtain one of these devices and troubleshoot it myself right now.

[^1]: We have a report of this happening on an Honor X6, but I want at least one more report of this happening on an Honor device before thinking of this as a confirmed issue on Honor devices.

kannel-outis commented 3 days ago

logcat gist

@andrewkolos

Phone information and flutter doctor output are provided in the gist.

shynriu commented 3 days ago

definitly is a problem with android 14, i tried my program with another phone, a oneplus 7 pro with android 12, it works

jemsoftie commented 1 day ago

flutter doctor -v, physical device, and logcat output

This is my first time using gist and logcat, so I had a hard time figuring out things HEHEHEHE.