Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dap-debug: The Android emulator exited with code 1 during startup #114

Closed
prasanthkrishnan opened this issue Aug 15, 2021 · 30 comments
Closed
Labels
bug Something isn't working

Comments

@prasanthkrishnan
Copy link

Describe the bug
I am trying to setup my doom emacs for flutter development. I am trying to launch the flutter_sample project via M-x dap-debug. It launches the android emulator but doesnt run the app. The next time I run M-x dap-debug I get the following error

[LSP Dart] [FLUTTER ERROR]  The Android emulator exited with code 1 during startup
[LSP Dart] [FLUTTER ERROR]  Android emulator stderr:
[LSP Dart] [FLUTTER ERROR]  Address these issues and try again.

I tried the following referring to this issue but still the problem persists.

  • removed and reinstalled dart-code-3.23.0.vsix
LSP :: Starting to download https://github.com/Dart-Code/Dart-Code/releases/download/v3.23.0/dart-code-3.23.0.vsix to /home/zerocool/.emacs.d/.local/etc/dap-extension/github/Dart-Code/Dart-Code/3.23.0/dart-code.zip...
Contacting host: github.com:443
Wrote /home/zerocool/.emacs.d/.local/etc/dap-extension/github/Dart-Code/Dart-Code/3.23.0/dart-code.zip
LSP :: Finished downloading /home/zerocool/.emacs.d/.local/etc/dap-extension/github/Dart-Code/Dart-Code/3.23.0/dart-code.zip...
LSP :: Decompressing /home/zerocool/.emacs.d/.local/etc/dap-extension/github/Dart-Code/Dart-Code/3.23.0/dart-code.zip...
(Shell command succeeded with no output)
LSP :: Decompressed /home/zerocool/.emacs.d/.local/etc/dap-extension/github/Dart-Code/Dart-Code/3.23.0/dart-code...
[LSP Dart] Dart debugger installed successfully!

  • Added export NO_PROXY=localhost,127.0.0.1 to zshrc file

To Reproduce
Dap-error

Expected behavior
** M-x dap-debug should run the app and initialize a dap session.

Version
Include here the result of: M-x lsp-dart-version
[LSP Dart] 1.19.0 at 2021.08.15 @ Emacs 27.2
[Dart SDK] Dart SDK version: 2.13.4 (stable) (Wed Jun 23 13:08:41 2021 +0200) on "linux_x64"

[Flutter SDK] /home/zerocool/snap/flutter/common/flutter
[Flutter project] true
[Project entrypoint] /home/zerocool/workspace/flutter_sample/lib/main.dart

Thanks in advance for the help!.

@ericdallo
Copy link
Member

Thanks for the report, is this reproducible for the same project if you run flutter run via terminal?

@ericdallo
Copy link
Member

Could you also get the output of the *Flutter Daemon* buffer?

@prasanthkrishnan
Copy link
Author

Thanks for the report, is this reproducible for the same project if you run flutter run via terminal?
flutter run via command line and M-x flutter-run-or-hot-reload succesfullt runs the app on the emulator.

dap error-follow1

Could you also get the output of the *Flutter Daemon* buffer?

[{"event":"daemon.connected","params":{"version":"0.6.0","pid":4061}}]
[{"event":"daemon.logMessage","params":{"level":"status","message":"Starting device daemon..."}}]
[{"id":99744}]
[{"event":"device.added","params":{"id":"chrome","name":"Chrome","platform":"web-javascript","emulator":false,"category":"web","platformType":"web","ephemeral":false,"emulatorId":null}}]
[{"event":"device.added","params":{"id":"emulator-5554","name":"sdk gphone x86 arm","platform":"android-x86","emulator":true,"category":"mobile","platformType":"android","ephemeral":true,"emulatorId":"Pixel_4a_API_30"}}]
[{"id":5635,"result":[{"id":"Pixel_4a_API_30","name":"Pixel 4a API 30","category":"mobile","platformType":"android"}]}]
[{"event":"daemon.logMessage","params":{"level":"error","message":"The Android emulator exited with code 1 during startup"}}]
[{"event":"daemon.logMessage","params":{"level":"error","message":"Android emulator stderr:"}}]
[{"event":"daemon.logMessage","params":{"level":"error","message":"Address these issues and try again."}}]
[{"id":85451}]
[{"id":14649,"result":[{"id":"Pixel_4a_API_30","name":"Pixel 4a API 30","category":"mobile","platformType":"android"}]}]
[{"event":"daemon.logMessage","params":{"level":"error","message":"The Android emulator exited with code 1 during startup"}}]
[{"event":"daemon.logMessage","params":{"level":"error","message":"Android emulator stderr:"}}]
[{"event":"daemon.logMessage","params":{"level":"error","message":"Address these issues and try again."}}]
[{"id":60207}]

@ericdallo
Feel free to ask more info. Thanks for looking into this!

@ericdallo
Copy link
Member

ericdallo commented Aug 15, 2021

@prasanthkrishnan my guess is that is a issue with the debugger extension we use (the same for vscode), could you check if changing lsp-dart-dap-extension-version to latest ("3.25.1") fixes the issue?

Also, could you try running in a different android emulator? just to check if the issue is not related to that emulator

@prasanthkrishnan
Copy link
Author

prasanthkrishnan commented Aug 15, 2021

my guess is that is a issue with the debugger extension we use (the same for vscode), could you check if changing lsp-dart-dap-extension-version to latest ("3.25.1") fixes the iss
To do that in doom emacs, steps are,

  • delete dart-code-3.23.0.vsix
  • Add this to config.el (setq lsp-dart-dap-extension-version "3.25.1")
  • doom sync
  • Rerun M-x lsp-dart-dap-setup

Also, could you try running in a different android emulator? just to check if the issue is not related to that emulator

Do you have anyone in particular, I am new to android development!
@ericdallo

@ericdallo
Copy link
Member

Rerun M-x lsp-dart-dap-setup

Same error?

Do you have anyone in particular, I am new to android development!

Usually, I test with Nexus 5/Nexus 5x

@prasanthkrishnan
Copy link
Author

Wanted to confirm the steps, give me a sec, I will report back!

@prasanthkrishnan
Copy link
Author

After installing dap vs code extension 3.25.1 and running nexus 5 API 30 emulator i get the same error. The app runs without issues with flutter run
@ericdallo

@ericdallo
Copy link
Member

Hum, I'd like to confirm if that could be a debugger issue.
Maybe @DanTup can help debug this on the debugger side?

@prasanthkrishnan
Copy link
Author

If it helps debugging, I am down for a screenshare session via discord / meet.

@DanTup
Copy link

DanTup commented Aug 16, 2021

I'm not very familiar with how things work in emacs-lsp so I'm not exactly sure what's wrong here. Is this issue when trying to launch the emulator, or run the app? These are two separate steps:

  • The emulator is launched via the daemon (or via flutter emulators --launch foo)
  • The app is run with flutter run which requires a device to already be available (in the case of an emulator, that it has already started)

The error in the daemon logs looks related to starting the emulator but the description sounds like the issue is with running the app. If the issue is with launching the app, then a log of all the DAP traffic would be helpful (with sendLogsToClient: true in the launch configuration).

@ericdallo
Copy link
Member

@DanTup thank you! @prasanthkrishnan could you try creating a new launch configuration with that sendLogsToClient: truesetting?
You can follow this example where it calls dap-register-debug-template

@prasanthkrishnan
Copy link
Author

prasanthkrishnan commented Aug 17, 2021

I added the following config.el and tried dap-debug

(after! lsp-dart
  (dap-register-debug-template "Flutter :: Custom debug"
                               (list :name "Flutter :: Custom Debug"
                                     :type "flutter"
                                     :sendLogsToClient t)))

There was no additional logs.

What i noticed is this, for the first time the emulator is starting fine but the app is not starting after the emulator comes up. When i try dap-debug again, it show the error mentioned above.

The Android emulator exited with code 1 during startup

I think it because there is already an existing emulator. So the problem here looks like the app not starting on the emulator. Thoughts? @ericdallo @DanTup

@DanTup
Copy link

DanTup commented Aug 17, 2021

What happens if you run flutter emulator --launch Pixel_4a_API_30 from a terminal?

@prasanthkrishnan
Copy link
Author

flutter_sample [ master][!?][🎯 v2.13.4]
❯ flutter emulator --launch Pixel_4a_API_30    
# launches the emulator (doesnt start the app)

# running the same command while the emulator is running
flutter_sample [ master][!?][🎯 v2.13.4]⏱ 3s
❯ flutter emulator --launch Pixel_4a_API_30
The Android emulator exited with code 1 during startup
Android emulator stderr:
Address these issues and try again.

@DanTup
Copy link

DanTup commented Aug 17, 2021

So it seems like starting the emulator works as long as it's not already running.

@ericdallo how does starting the emulator work in lsp-dart? Is it part of starting the debug session or separate? If the same, does it check the device isn't already running before trying to start it? Could it be trying to load it each time, and this error preventing it from then starting the debug session via the DAP?

@ericdallo
Copy link
Member

Good point @DanTup @prasanthkrishnan, probably it's missing some check that use to not be a issue before on lsp-dart, @DanTup how Dart-Code check if the emulator is already running? I can try to implement the same check

@DanTup
Copy link

DanTup commented Aug 17, 2021

Dart-Code doesn't really launch on emulators, only on devices. So whenever you try to launch if there is an active device (or one explicitly specified), it will use that. If not, it shows a list of emulators and you can pick to launch one, but it just relies on the fact that it will shortly turn up in the device list when it's finished booting, so it will then auto-select that and use it.

So it never really needs to know whether an emulator is running. However, it actually does check that, only to filter out the emulators from the emulator list that already have active devices (just to avoid confusion with emulators showing up twice - once as an (unbooted) emulator and once as a (running) device). It does this using the emulatorId fields from the device daemon to hide those emulators from the emulator list.

[{"event":"device.added","params":{"id":"emulator-5554","name":"sdk gphone x86 arm","platform":"android-x86","emulator":true,"category":"mobile","platformType":"android","ephemeral":true,
  "emulatorId":"Pixel_4a_API_30"
}}] 
``

@ericdallo
Copy link
Member

Thank you @DanTup ! I'll try to improve that on lsp-dart side

@ericdallo
Copy link
Member

Hey @prasanthkrishnan I manage to reproduce the issue for emulators that were already running.
I just pushed to master a fix for that, lsp-dart now check if the emulator is running before try to launch and we now correctly filter the emulator to avoid duplicated emulators on the list just like @DanTup said Dart-Code does, could you confirm it works for you so I can release a fix?

@prasanthkrishnan
Copy link
Author

I test the fix and it worked perfectly.
@ericdallo @DanTup Thanks for the help!

@ericdallo
Copy link
Member

Great, thanks for the details, debugging and help @DanTup @prasanthkrishnan
I'll release a new version soon

@ericdallo ericdallo added the bug Something isn't working label Aug 19, 2021
@DanTup
Copy link

DanTup commented Aug 19, 2021

Great! :-)

Btw @ericdallo do you only ever use the Flutter version of Dart-Code's DAP, or also the Dart CLI one? I'm working on moving DAP to the SDK (and will migrate Dart-Code to it), though it'll likely be in two parts (the Dart part in the Dart SDK and Flutter part in the Flutter SDK). When it's a bit more complete it may be useful to have you try it out (it's had a little cleanup so some of the arguments passed are slightly different and it supports a better way for the editor to inform the DAP which folders are the users code).

@ericdallo
Copy link
Member

Oh good to know that! lsp-dart support both flutter debugger and dart debugger so I think it depends on both?
Also, it'd be really helpful if there is a page or some docs with the available flags, last time I needed to debug Dart-Code code to see what flags it was sending and what flags the debugger was receiving 😅 anyway, thanks for the heads up, LMK when things are ready for that migration on clients

@DanTup
Copy link

DanTup commented Aug 19, 2021

it'd be really helpful if there is a page or some docs with the available flags, last time I needed to debug Dart-Code code to see what flags it was sending and what flags the debugger was receiving 😅

Yes, there will be one :) I haven't documented it properly yet as it's not really ready for people to use (you currently have to run it from a clone of the SDK, but it should ultimately be some SDK command like dart dap or similar). The Dart-Code one wasn't really intended for other clients so that wasn't well documented either (and it didn't really matter what they were called when I was both sides).

Once there's a good way to start the DAP, I'll create a doc like the LSP one that includes what's supported and any custom fields/events/requests that are implemented. I'll ping you somewhere when that's the case :-)

@ericdallo
Copy link
Member

That sounds great! thank you very much!

@DanTup
Copy link

DanTup commented Apr 6, 2022

@ericdallo not sure if I'd mentioned this elsewhere, but using the current dev/master versions of Dart/Flutter, the SDK DAPs should be pretty good now. Info can be found here:

Dart: https://github.com/dart-lang/sdk/blob/main/pkg/dds/tool/dap/README.md
Flutter: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/debug_adapters/README.md

To start them, you can use dart debug_adapter and flutter debug_adapter and not need anything from Dart-Code. I plan to start migrating VS Code to those adapters after the next stable release.

@ericdallo
Copy link
Member

@DanTup yes! I implemented it some weeks ago, and released a new lsp-dart version already using it, it looks awesome!

@ericdallo
Copy link
Member

We are basically checking flutter/dart version is supports that and using it behind a enabled flag by default:

`(,(lsp-dart-dart-command) "debug_adapter")

@DanTup
Copy link

DanTup commented Apr 6, 2022

Great! I thought we'd discussed it somewhere, but couldn't see where (I found this notification in my mailbox waiting to be pinged 😄).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants