35

I've been pulling my hair over this for 3 days now,

every time I run the command react-native run-android I get this error:

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
(node:10284) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
Jetifier found 871 file(s) to forward-jetify. Using 16 workers...
info JS server already running.
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\Java\jdk-17\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\Java\jdk-17\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

    at makeError (C:\Users\username\Desktop\code\React Native\Build App\Scheduler\node_modules\execa\index.js:174:9)
    at C:\Users\username\Desktop\code\React Native\Build App\Scheduler\node_modules\execa\index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async runOnAllDevices (C:\Users\username\Desktop\code\React Native\Build App\Scheduler\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:106:5)
    at async Command.handleAction (C:\Users\username\Desktop\code\React Native\Build App\Scheduler\node_modules\react-native\node_modules\@react-native-community\cli\build\index.js:192:9)info Run CLI with --verbose flag for more details.

I created my directory using basic react-native init projectTesting

My gradle is version 6.9
.\android\gradle\wrapper\gradle-wrapper.properties =>distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip

My android studios version is Android Studio 2020.3.1

My java version is 15

C:\Users\username>java -version
java version "15" 2020-09-15
Java(TM) SE Runtime Environment (build 15+36-1562)
Java HotSpot(TM) 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)

C:\Users\username>javac -version
javac 15

I was thinking of using java 17 but in the compatibility docs it said:

A Java version between 8 and 15 is required to execute Gradle. Java 16 and later versions are not yet supported when executing Gradle.

any help would be really really appreciated!!

  • can you try " echo %JAVA_HOME% " command with your terminal ? its weird because its looking for C:\Program Files\Java\jdk-17\bin\java.exe and your version is 15 . – George Oct 05 '21 at 10:15
  • @George it returns `C:\Program Files\Java\jdk-15\bin\` –  Oct 05 '21 at 10:22
  • Can you share the build.gradle file ? or even just check for sourceCompatibility and targetCompatibility . and can you check if there is any global values in your .gradle/gradle.properties ? – George Oct 05 '21 at 10:33
  • @George here's a link to my build.gradle file: https://justpaste.it/29x2w –  Oct 05 '21 at 10:45
  • Oh , how did i miss that , You have an extra \bin in your java home , can you try remove it ? if this did not work Add this to gradle.properties in /user/.gradle folder " org.gradle.java.home = C:\Program Files\Java\jdk-15 "but with out the \bin , The \bin should be added to PATH not to java home – George Oct 05 '21 at 11:29
  • @George oh yea I just saw that I accidently have both folders jdk-15 and jdk-17 , I deleted the jdk-17 folder and now the emulator is starting but it isn't loading the app on it and is giving this error https://justpaste.it/1nssi –  Oct 05 '21 at 13:55
  • @George okay interesting development, I first deleted the jdk-17 folder and then uninstalled 31 and 30 version of sdk build tools and it started working again, you can post this as an answer I'll mark it correct –  Oct 05 '21 at 14:27

12 Answers12

97

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 or rename the jre folder, run cmd as administrator and create a symbolic link:

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

Thanks to this link

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
Nicks
  • 3,188
  • 3
  • 25
  • 29
  • 1
    This does break the update to Android Studio Electric Eel | 2022.1.1 Patch 1 though. The updater needs contents of the jre folder to follow a specific pattern. So it's better to not remove the jre folder but instead to rename it to jre_old. – Harmen Feb 04 '23 at 16:33
  • If this breaks your update to patch 1 download the current version of android studio and repair the jre folder by unzipping the jr folder from the zip. Following this comment: https://stackoverflow.com/a/50187359/1636247 – Harmen Feb 08 '23 at 18:30
  • 3
    Without deleting the jre folder just renaming it worked for me. – Semih Yilmaz Feb 15 '23 at 15:05
56

after update to Android Studio 22.1.1, just delete folder jre in C:\Program Files\Android\Android Studio it works for me

cwang
  • 561
  • 2
  • 2
  • 3
    that did it for me for 2022.1.1 as well; after spending an hour working with JAVA_HOME and JRE_HOME and the likes, thanks, @cwang – roetzi Jan 14 '23 at 09:49
  • I just read, "you have to delete Android Studio" :D – Szabo Gabor Feb 22 '23 at 12:21
  • WOW!!! And here I was about to duplicate a bunch of files from jbr to jre. Apparently if it doesn't find the jre folder it looks into the jbr. – Dpedrinha Aug 18 '23 at 19:28
  • deleting/renaming dummy `jre` folder solves the problem even for the recent Android Studio 2022.3.1.19 (Windows). I wonder why this issue isn't fixed officially. – AntonK Aug 24 '23 at 19:07
19

Deleting Java17 SDK and C:\Program Files\Java folder worked for me. Use openjdk11 instead of Java17 SDK

Fedor
  • 17,146
  • 13
  • 40
  • 131
MuhammedBalta
  • 472
  • 5
  • 14
13

Copy contents of this folder

C:\Program Files\Android\Android Studio\jbr

INTO THIS FOLDER

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

DONE

Lewin Muzvonda
  • 310
  • 2
  • 10
  • Actually, just deleting the jre folder solves the problem. Apparently there's a fix to make the IDE look into the jbr folder IF it doesn't find the old jre. – Dpedrinha Aug 18 '23 at 19:27
10

Make sure of your JAVA_HOME Path in your terminal with

echo %JAVA_HOME%

Its a common mistake to have \bin , while \bin should be in the PATH the java home is only your jdk folder like C:\Program Files\Java\jdk-15 .

Deleted the jdk-17 folder and then uninstalled 31 and 30 version of sdk build tools and this should fix the issue .

George
  • 2,292
  • 2
  • 10
  • 21
5

I faced the problem as I have multiple sdks, e.g 1.8 inside my java folder along with java 11. Deleted other jdks except 11 worked for me.

K_Chandio
  • 558
  • 1
  • 7
  • 16
  • What lousy piece of software. I had set up the java home correctly and yet it picked up that empty folder everytime. – Meghdad Aug 21 '23 at 14:57
  • Yes, setting up java and android environment is hectic. Did you tried restarting your pc to avoid caches? – K_Chandio Aug 22 '23 at 12:19
  • actually on a second investigation,I found it was my bad because the path was not set correctly using powershell. The syntax is different from that of CMD. – Meghdad Aug 24 '23 at 10:21
5

Go to C:\Program Files\Android\Android Studio You will find the "jbr" directory and the "jre" directory copy the content of the "jbr" directory into the "jre" directory.

Run your project again. It should work now.

Note:

  • you may have to delete the bin inside the "jre" first if refuse to paste.
  • you may have to check the environment variable.
4

The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files\Java\jdk1.8.0_341\bin\java

I was in a similar problem and you can solve it in the following way --> Go to Disk C, Find the java folder in android and delete the previous version of jdk by default it comes with 1.8 C:\Program Files\Java for Reac native version 11 of jdk is recommended.

Jdone
  • 41
  • 1
3

Copying all the contents from the bin folder of my Java installation directory C:\Program Files\Java\jdk-19\bin to the Android Studio jre folder C:\Program Files\Android\Android Studio\jre\bin helped fix the problem when using Android Studio Flamingo | 2022.2.1 Patch 1 Build #AI-222.4459.24.2221.9971841, built on April 19, 2023 and Java 19 SDK

I did this, because the reason why the java executable can't be found at the tried location: C:\Program Files\Java\jdk-17\bin\java.exe is because it doesn't exist there, so we can put it there with ease via copy and paste of the bin contents as I did above. I hope this helps.

1

I get help from other answers and with my tries i find this solution:

  1. Delete jdk folder in Android Studio directory
  2. Change path in Windows Env. Variables JAVA_HOME: .../Android Studio/jdk => .../Android Studio/jbr
  3. Restart your IDE
0

just open the program files folder and navigate to the android folder then open the android folder and then cut all the file from jbr folder to jre folder make to replace all the file when you paste the cut files from the jbr folder i think this will surely work for all .

  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 13 '23 at 01:43
0

i solved this issue , just go to "Environment variables" and add JAVA_HOME with value of java path

enter image description here

MikeNabil
  • 81
  • 6