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

I tried to run my flutter android project from github repo with emulator, but this error comes up

2 Likes

I had same problem.
to solve the issue, I created a flutter project using idx itself.
there in directory idx gave a folder “.idx” and a file “dev.nix” inside it.
you just also need to create “.idx” folder in your project imported from github and “dev.nix” file inside this folder and copy paste the code of “dev.nix” file.

then run your app, it might crash for the first time, but run it again and it’ll work.

Can you explain in detail ?

JAVA HOME error is coming because IDX uses its own environment to set all variables like JAVA HOME.
When you import github repo as a IDX project, IDX actually does not know about its configuration.

So just to fix the configuration I followed following steps:

  1. create a new flutter project in idx.
  2. open your flutter project in idx as well in new tab.
  3. create .idx folder in root directory of your flutter project (github one)
  4. copy and paste the dev.nix file from newly created .idx folder into your recently created .idx folder in your flutter project.
  5. run your flutter code, it might crash for first time, But it will run with all configuration including JAVA HOME.

In .idx/dev.nix add:

packages = [
    pkgs.jdk11
    # pkgs.python311
    # pkgs.python311Packages.pip
    # pkgs.nodejs_20
    # pkgs.nodePackages.nodemon
  ];

swith the java version that you need.

Note: to flutter projects use java 11.

1 Like

Appreciate the replies everyone! As other have mentioned, java needs to be added manually in dev.nix for imported projects by adding pkgs.jdk (ex: jdk11, jdk17) to the packages list.