Home > database >  Android Studio Electric Eel: javaHome seems to be invalid
Android Studio Electric Eel: javaHome seems to be invalid

Time:01-14

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

CodePudding user response:

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.

CodePudding user response:

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.

  • Related