Khamidjon Khamidov
Khamidjon Khamidov

Reputation: 8909

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

I installed Android Studio 4.1 and tried to run the existing project. But it gives an error like this:

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.

Upvotes: 94

Views: 259657

Answers (16)

I set my JAVA HOME to the path,

/snap/android-studio/97/android-studio/jre/

Then I set my android studio config in flutter by using this command:

flutter config --android-studio-dir=/snap/android-studio/current/android-studio

My system is : Ubuntu 20.04 with Flutter plugin version as 4.1,

Upvotes: 3

Zorencen R
Zorencen R

Reputation: 576

For Debian 12 and Ubuntu 22.04.

sudo apt install openjdk-17-jdk

Upvotes: 0

anil kr maurya
anil kr maurya

Reputation: 29

For Windows this worked

Go to C:\Program Files\Android\Android Studio.
Copy all the files inside of jbr directory.
Paste all the files into jre directory.
Then run flutter doctor. The issue will go away.

D:\Flutterproject\rechyriedapp>flutter doctor -v
[√] Flutter (Channel stable, 3.3.8, on Microsoft Windows [Version 10.0.22621.1105], locale en-IN)
    • Flutter version 3.3.8 on channel stable at C:\flutter_windows_3.3.8\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 52b3dc25f6 (3 months ago), 2022-11-09 12:09:26 +0800
    • Engine revision 857bd6b74c
    • Dart version 2.18.4
    • DevTools version 2.15.0

[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\Users\USER\AppData\Local\Android\Sdk
    • Platform android-TiramisuPrivacySandbox, build-tools 33.0.0
    X No Java Development Kit (JDK) found; You must have the environment variable JAVA_HOME set and the java binary in your PATH. You can download the JDK from https://www.oracle.com/technetwork/java/javase/downloads/.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.4.4)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.4.33213.308
    • Windows 10 SDK version 10.0.22000.0

[!] Android Studio (version 2022.1)
    • 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
    X Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[√] Connected device (4 available)
    • CPH2095 (mobile)  • 86db9605 • android-arm64  • Android 12 (API 31)
    • Windows (desktop) • windows  • windows-x64    • Microsoft Windows [Version 10.0.22621.1105]
    • Chrome (web)      • chrome   • web-javascript • Google Chrome 109.0.5414.120
    • Edge (web)        • edge     • web-javascript • Microsoft Edge 109.0.1518.55

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 2 categories.

After that copy all file from jbr to jre

D:\Flutterproject\rechyriedapp>flutter doctor -v
[√] Flutter (Channel stable, 3.3.8, on Microsoft Windows [Version 10.0.22621.1105], locale en-IN)
    • Flutter version 3.3.8 on channel stable at C:\flutter_windows_3.3.8\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 52b3dc25f6 (3 months ago), 2022-11-09 12:09:26 +0800
    • Engine revision 857bd6b74c
    • Dart version 2.18.4
    • DevTools version 2.15.0

Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\Users\USER\AppData\Local\Android\Sdk
    • Platform android-TiramisuPrivacySandbox, build-tools 33.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.4.4)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.4.33213.308
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2022.1)
    • 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 11.0.15+0-b2043.56-8887301)

[√] Connected device (4 available)
    • CPH2095 (mobile)  • 86db9605 • android-arm64  • Android 12 (API 31)
    • Windows (desktop) • windows  • windows-x64    • Microsoft Windows [Version 10.0.22621.1105]
    • Chrome (web)      • chrome   • web-javascript • Google Chrome 109.0.5414.120
    • Edge (web)        • edge     • web-javascript • Microsoft Edge 109.0.1518.55

[√] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Upvotes: 0

Sidharth Mudgil
Sidharth Mudgil

Reputation: 1461

Locate where your Android Studio is installed.

For me C:\Program Files\Android\Android Studio

  1. Check if the jre folder exists, Create a new folder called jre
  2. Copy the contents of the jbr folder and paste them into the jre folder.
  3. Check by running flutter doctor, and Restart IDE.

Thanks: roufy235 {cause}

Upvotes: 10

ALI USAMA
ALI USAMA

Reputation: 345

This issue can also be caused if you have updated your Android Studio.

In that case.

For Windows


First Open the Users\username\AppData\Local\Google directory on your PC/Laptop and make sure to Delete the older version of your Android Studio.

e.g, Current version of Android studio is Electric Eel (2022.1).

Delete any other older version from that directory accordingly and restart your PC or Laptop.

Then try running your project.

Upvotes: 4

Dinu Nicolae
Dinu Nicolae

Reputation: 1281

choco install javaruntime

If you use choco package manager. It will set the vars automatically.

Upvotes: 1

MendelG
MendelG

Reputation: 20038

You have to set the JAVA_HOME Environment Variable.

On Windows, I solved the issue as follows:

  1. Download the Java JDK from here and install it. (This links to version 15, which requires you to create an account in order to download. Version 16 is available to download without creating an account, but it has caused me an error that required me to downgrade.)

  2. Set the "JAVA_HOME" Environment Variable:

    • Open Windows Search, type in “env”, and choose “Edit the system environment variables”.

      enter image description here

    • Click on "Environment Variables...".

    • Click on "New".

    • Fill in the "variable name" field with "JAVA_HOME".

    • Fill in the "variable value" with the path to where Java is installed on your computer. (for me it was under "C:\Program Files\Java\<jdkversion>".)

      Screenshot

    • Click "OK" and close all dialogs.

  3. Restart your IDE / Terminal. (do not skip this step)

Upvotes: 97

Krishna
Krishna

Reputation: 11

Download Liberica JDK and on installation it will automatically set JAVA_HOME environment variable. Now you just go to Android Studio -> Project Structure -> SDK -> Point all jdk path to liberica jdk installation directory and apply. You are done. Just restart android studio and gradle command will work.

Upvotes: 0

RileyManda
RileyManda

Reputation: 2641

In Mac:

In your terminal run

ECHO $JAVA_HOME

This will bring up the current path of java home.Pay close attention to the path that the terminal outputs.In my case i had System/Library instead of /Library/.../... typo as my path.So i simply corrected this in bash_profile.

If your path is correct but the error persists,

Right Click On Finder

Go To Folder

Go To Folder

Bash_Profile

Bash_Profile

Add or Edit the Java Home Path

The path you add here should be the one your terminal output when you ran Echo $Java_Home..As long as this path that was echoed was/is correct..the below steps should fix the issue.

echohome

Add or Edit the Java Home Path

Then open your zshrc in a similar manner as you did with bash_profile and add the home path to the file.

zshrc file

You can also edit the bash_profile and zshrc files in your text editor.These files can be displayed using cmd + shift + . in your home folder.

bashprofile and zshrc

After that,save,exit the terminal, close android studio and restart your machine.

Read this Article to learn more.

Upvotes: 4

dilshan
dilshan

Reputation: 2522

  1. Install Android Studio (skip this step if you already installed)

  2. Goto C:\Program Files\Android\Android Studio\jre and copy the path.

  3. Make New variable called "JAVA_HOME". And paste above path as the variable value.

enter image description here

Upvotes: 10

Shubham Gupta
Shubham Gupta

Reputation: 1353

For Windows :

flutter config --android-studio-dir="C:\Program Files\Android\Android Studio"

This command works fine if you have Android Studio installed. Flutter can understand the configurations of the Android Studio and you don't have to provide JAVA_HOME anymore.

Edit (Bonus) :

Also, download "Android SDK Command-line Tools" in android studio for android-licenses. Steps are shown in the image below.

enter image description here

Upvotes: 34

Joseph Ajibodu
Joseph Ajibodu

Reputation: 1656

Install openjdk-8 ....

You have to restart your terminal, the issue will persist even after download if you don't restart the terminal.

Follow react native guide to download openjdk for your environment. ...

https://reactnative.dev/docs/environment-setup

Upvotes: 0

Maheep
Maheep

Reputation: 897

For ubuntu 20.04 this solution will be appropriate: -

This link solved my problem. In short I would recommend to follow the simple steps, i.e.

  • Upgrade the flutter using flutter upgrade
  • Set the path of the flutter flutter config --android-studio-dir="/path/to/android/studio/"
  • Set the path in bashrc file by opening bashrc file(it is a hidden file)
    export JAVA_HOME="/path/to/android/studio/jre/"

Upvotes: 1

Rony Mesquita
Rony Mesquita

Reputation: 559

On Ubuntu 20.04 with Android 4.1, this error can be solved using the Snap version with:

flutter config --android-studio-dir=/snap/android-studio/current/android-studio

Upvotes: 27

Joseph P
Joseph P

Reputation: 143

UPDATE: run flutter upgrade to upgrade to Flutter 1.22.2, which fixes compatibility issues with Android Studio 4.1. See related Flutter release.

This issue has been resolved v

See this issue regarding Android Studio 4.1 and Flutter

You can either downgrade back to Android Studio 4.0.2 or you can install the latest JDK and update your JAVA_HOME variable and PATH (OS dependent).

Note that if you choose to continue using 4.1 instead of downgrading, flutter doctor will tell you Android Studio is not installed.

You need to run flutter config --android-studio-dir='<path to android studio>' in order to fix this issue. flutter doctor will now also incorrectly report that the Flutter and Dart plugins are not installed even if they are - you can ignore this.

Upvotes: 10

Matthias
Matthias

Reputation: 426

You need to install Java JDK software which is required for the android studio.

sudo apt install openjdk-11-jdk

Upvotes: 18

Related Questions