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

lsp-dart-run can't find a java executable or JAVA_HOME #194

Open
toniz4 opened this issue Mar 19, 2023 · 5 comments
Open

lsp-dart-run can't find a java executable or JAVA_HOME #194

toniz4 opened this issue Mar 19, 2023 · 5 comments

Comments

@toniz4
Copy link

toniz4 commented Mar 19, 2023

Describe the bug

When trying to run lsp-dart-run, using envrc to populate the env variables based on a shell.nix. The debbuger or runner exits with the following message:

Launching lib/main.dart on sdk gphone64 x86 64 in debug mode...

ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Exception: Gradle task assembleDebug failed with exit code 1

The weird thing is, the flutter and dart executables and sdks and the jdk are being set up in the same way, at the same time. So, if the flutter command is avaliable to emacs, I don't know why it only fails with the java command.

To Reproduce

Have JAVA_HOME and the java executable path set by envrc.
Run dap-debug or lsp-dart-run in a flutter project.

Expected behavior
That lsp-dart-run executes my app

Version

[LSP Dart] 1.24.1 at 2023.03.19 @ Emacs 28.2
[Dart SDK] Dart SDK version: 2.18.4 (stable) (Tue Nov 1 15:15:07 2022 +0000) on "linux_x64"

[Flutter SDK] /nix/store/zdvb6d47hnmgp6ccsm7n6jr60q3yczfb-flutter-3.3.8-unwrapped
[Flutter project] true
[Project entrypoint] /home/cassio/src/namer_app/lib/main.dart

What I think is hapening is that somewere, the process-environment and exec-path are being reseted to the default value, I tried to identify where, but my skills to debug elisp are not the best. But I found those possible related issues:

greghendershott/racket-mode#539
rust-lang/rust-mode#447
magit/magit#4160
purcell/envrc#31

@ericdallo
Copy link
Member

I suspect is related with the shell process spawned by dart to run java is using a "default" shell which is not the same emacs or your terminal is using

@toniz4
Copy link
Author

toniz4 commented Apr 20, 2023

I suspect is related with the shell process spawned by dart to run java is using a "default" shell which is not the same emacs or your terminal is using

I think that is the poblem too. It's not inheriting the "main buffer" (the one i'm executing lsp-dart-run) process-environment and exec-path, so it can't find the java executable or JAVA_HOME. But it's able to run flutter for some reason.

Do you know where this process is being started?

@ericdallo
Copy link
Member

I don't know, but I use doom and they use https://github.com/purcell/exec-path-from-shell IIRC which fix most errors like that

@toniz4
Copy link
Author

toniz4 commented May 9, 2023

I don't know, but I use doom and they use https://github.com/purcell/exec-path-from-shell IIRC which fix most errors like that

I use doom here too, but I found a possible solution. If I add

  (dap--put-if-absent conf :environment-variables '(("GRADLE_OPTS" . "-Dorg.gradle.project.android.aapt2FromMavenOverride=/nix/store/3svzmqsal084m2wffsj7drqk2kzi514c-android-sdk-env/share/android-sdk/build-tools/33.0.2/aapt2")))

To lsp-dart-dap--base-debugger-args, I'm able to run flutter just fine. There's a less intrusive way that I can do that? If there's not, if it's applicable, I could make a PR adding a variable to add custom debugger args.

@ericdallo
Copy link
Member

@toniz4 you can create your own debugging template to customize that via:

(dap-register-debug-template "Flutter :: Debug with custom env vars"
                             (list :type "flutter"
                                   :environment-variables '(("GRADLE_OPTS" . "-Dorg.gradle.project.android.aapt2FromMavenOverride=/nix/store/3svzmqsal084m2wffsj7drqk2kzi514c-android-sdk-env/share/android-sdk/build-tools/33.0.2/aapt2"))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants