Ubuntu java_home is not set and no java command could be found in your path.

I'm having a problem running my flutter application in android studio.

It gives me the following message

Launching lib/main.dart on sdk gphone x86 in debug mode... Running Gradle task 'assembleDebug'... 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

Here is echo $JAVA_HOME and I have added the bin to my PATH

/usr/lib/jvm/openjdk-14.0.2_linux-x64_bin/jdk-14.0.2

I can run flutter from terminal via flutter run after upgrading gradle from gradle-5.6.2-all.zip to gradle-6.3-all.zip

I think the problem lies in android/gradlew in the following script

# Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else JAVACMD="java" which java >/dev/null 2>&1 || die "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." fi

I tried copying it and running it and it runs with no problems with #!/usr/bin/env bash which is the shebang in gradlew

I tried reinstalling android studio, but it didn't work. My flutter doctor --verbose is a mess. At first it couldn't find android studio- said it is not installed. so I ran flutter config --android-studio-dir="/snap/bin" but now I get this output even though I have the plugins installed

:~$ flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 1.22.4, on Linux, locale en_US.UTF-8) [!] Android toolchain - develop for Android devices (Android SDK version 30.0.2) ✗ Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses. See //flutter.dev/docs/get-started/install/linux#android-setup for more details. [!] Android Studio ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. ✗ android-studio-dir = /snap/bin ✗ Unable to find bundled Java version. [!] Connected device ! No devices available ! Doctor found issues in 3 categories. :~$ flutter doctor --android-licenses Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156) at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75) at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81) at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73) at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48) Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ... 5 more

Thank you all hopefully I'm missing something simple!

[

I installed Android Studio 4.1 and trying to run existing project. But it gives 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.

,

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”.

    • 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>”)

    • Click “OK” and close all dialogs.

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

,

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

,

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.

,

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

sudo apt install openjdk-11-jdk

,

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.

,

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,

,

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/"

,

  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.

,

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. …

//reactnative.dev/docs/environment-setup

,

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

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.

Then open your zshrc in a similar manner as you did with bash_profile and add the home path to the 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.

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

Read this Article to learn more.

]

Toplist

Neuester Beitrag

Stichworte