skip to Main Content

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 FilesJavajdk-19. I can change to C:Program FilesAndroidAndroid Studiojbr which has binjava.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 FilesAndroidAndroid Studiojrebinjava.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 FilesAndroidAndroid Studiojrebinjava.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

7

Answers


  1. The error message is indicating that the JAVA_HOME environment variable is set to an invalid location, specifically "C:Program FilesAndroidAndroid Studiojrebinjava.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 FilesAndroidAndroid Studiojdk". 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.

    Login or Signup to reply.
  2. 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 FilesAndroidAndroid Studiojbr

    2. Open File Explorer and Navigate to C:Program FilesAndroidAndroid Studiojbr and copy everything and paste it to C:Program FilesAndroidAndroid Studiojre

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

    Login or Signup to reply.
  3. For Windows:

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

    C:Program FilesAndroidAndroid Studiojre

    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"
    
    Login or Signup to reply.
  4. 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"
    
    Login or Signup to reply.
  5. 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 FilesAndroidAndroid Studio) remove jre folder run cmd as administrator

    cd C:Program FilesAndroidAndroid Studio mklink /D "jre" "jbr"

    Login or Signup to reply.
  6. 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.

    Login or Signup to reply.
  7. For Mac Users, we can use simply below commands to fix this issue

    cd /Applications/Android Studio.app/Contents
    
    ln -s jbr jre 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search