aman
aman

Reputation: 391

Android Studio Electric Eel: javaHome seems to be invalid

I'm developing a React Native - TypeScript Mobile app. I updated Android Studio which has ruined the build of my app. I have spent multiple hours but I'm not able to resolve the JAVA_HOME error I keep getting. Need help.

Installed Android Studio:

Android Studio Electric Eel | 2022.1.1
Build #AI-221.6008.13.2211.9477386, built on January 11, 2023
Runtime version: 11.0.15+0-b2043.56-8887301 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 1280M
Cores: 8
Registry:
    external.system.auto.import.disabled=true
    ide.text.editor.with.preview.show.floating.toolbar=false

JAVA_HOME is set to C:\Program Files\Java\jdk-19. I can change to C:\Program Files\Android\Android Studio\jbr which has \bin\java.exe.

Error on running react-native run-android:

info Starting JS server...
info Installing the app...

FAILURE: Build failed with an exception.

* What went wrong:
The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files\Android\Android Studio\jre\bin\java.exe

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files\Android\Android Studio\jre\bin\java.exe

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Upvotes: 12

Views: 14572

Answers (8)

Monirul Islam
Monirul Islam

Reputation: 1

Well, I solved this problem. You should delete the "jre" folder from "C:\Program Files\Android\Android Studio" and reset your Android Studio ide and run again.

Upvotes: 0

Raj008
Raj008

Reputation: 3927

For Mac Users, we can use simply below commands to fix this issue

cd /Applications/Android\ Studio.app/Contents

ln -s jbr jre 

Upvotes: -1

Raj008
Raj008

Reputation: 3927

For Mac Users:

Make sure you have installed java and set the java_home path, you can use homebrew for that. NB If you installed Android Studio Electric Eel Follow the following step

Go to your Applications folder. Search for Android Studio Right click and select Show Package Content. Navigate into the Content Folder that opens. Create NewFolder jre and copy content from jbr.

Upvotes: 0

Nicks
Nicks

Reputation: 3502

If someone faces this error after Android Studio update to Android Studio Electric Eel | 2022.1.1 than simply follow following steps:

Go To android studio directory (Default C:\Program Files\Android\Android Studio) remove jre folder run cmd as administrator

cd C:\Program Files\Android\Android Studio mklink /D "jre" "jbr"

Upvotes: 2

AVEbrahimi
AVEbrahimi

Reputation: 19184

For Windows:

The problem is because of trace of old Android Studio java folder, just delete this folder and it starts working:

C:\Program Files\Android\Android Studio\jre

The new Android Studio Electric Eel is using jbr, not jre.


For macOS as @Jayanth replied above: If you are using macOS replace the path in .bash_profile or .zshrc

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"

with

export JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home"

Upvotes: 20

Jayanth
Jayanth

Reputation: 6297

If you are using MAC replace the path in .bash_profile or .zshrc

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"

with

export JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home"

Upvotes: 5

Ravi Kumar
Ravi Kumar

Reputation: 4528

I was also getting the same issue on my Kotlin Android Project after updating the android studio. This seems to be a bug. THe below steps worked for me:

  1. Update JAVA_HOME to C:\Program Files\Android\Android Studio\jbr

  2. Open File Explorer and Navigate to C:\Program Files\Android\Android Studio\jbr and copy everything and paste it to C:\Program Files\Android\Android Studio\jre

  3. Restart your PC and try to run the project again.

Upvotes: 8

Rares
Rares

Reputation: 11

The error message is indicating that the JAVA_HOME environment variable is set to an invalid location, specifically "C:\Program Files\Android\Android Studio\jre\bin\java.exe", which doesn't contain the java executable.

It seems that after updating Android Studio, the location of the JDK has been changed. You can try the following steps to fix the issue:

  • Locate the JDK directory on your computer. It should be in the same location as Android Studio, for example, "C:\Program Files\Android\Android Studio\jdk". Make sure that the directory contains the java.exe executable.

  • Update the JAVA_HOME environment variable to point to the correct JDK directory. You can do this by going to System Properties > Advanced > Environment Variables, and then editing the JAVA_HOME variable to point to the correct location.

  • Restart your terminal or command prompt and try running the "react-native run-android" command again.

  • If the problem persist, you can delete your current JDK installation and install it again.

Another solution is to check your Android Studio settings and make sure that the JDK location is correct under the "Appearance & Behavior > System Settings > Android SDK" settings.

Also make sure that you have set the JAVA_HOME environment variable in the system environment variables and not just in the user variables.

Upvotes: 0

Related Questions