Android Studio Electric Eel: javaHome seems to be invalid - android

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

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"

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:
Update JAVA_HOME to C:\Program Files\Android\Android Studio\jbr
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
Restart your PC and try to run the project again.

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"

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"

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.

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.

For Mac Users, we can use simply below commands to fix this issue
cd /Applications/Android\ Studio.app/Contents
ln -s jbr jre

Related

Where does 'flutter doctor --android-licenses' look for 'JAVA_HOME' on MacOS(10.15.7)?

System: MacOS Catalina (10.15.7), MacBook Pro 2018
When I run:
flutter doctor
I see that I need to accept the android licenses, so I run:
flutter doctor --android-licenses
Which gives me the following error:
ERROR: JAVA_HOME is set to an invalid directory: /Applications/Android Studio 3.5.app/Contents/jre/jdk/Contents/Home
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
Checking my environment variables:
env | grep JAVA_HOME
JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
I went so far as to uninstall all my Android Studio installations.
I checked /etc/profile; ~/.profile; ~/.zprofile; ~/.zshrc and none of these have an entry for JAVA_HOME
I went ahead and added an entry to ~/.zshrc to mirror what's reported by env.
No change, I get the same error.
Anyone have any insight?
Not sure if this is standard, but I looked inside the sdkmanager script located here:
/Users/<myusername>/Library/Android/sdk/tools/bin
and it contained an entry for the old version of Android Studio 3.5.
I updated the entry to point to the latest installed Android Studio, i.e. I dropped the version number.
Now everything is fine.
I'm guessing my initial install of the Android SDK was when I installed Android Studio 3.5 and had named added the version number prior to dragging the app into the Applications directory.

How to debug "Build failed with an exception / SDK location not found" in Android?

I'm new in React-Native. I tried several solution in some forums but didn't help. Bellow the errors .
Microsoft Windows [Version 10.0.17134.407]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\xampp\htdocs\Hands-on React-Native\TripPlane>react-native run-android
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
* 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
BUILD FAILED in 19s
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
You need to setup ReactNative properly.
I have consider that android studio is already installed and emulator or android device is already attached
Follow below steps!
1] Install JDK from official site
2] Install NodeJs from official site
3] Install Python 2 form official site
4] Install ReactNative CLI , open CMD [ right click and run as administrator ]
Type C:\WINDOWS\system32>node -v // to get node version
Type C:\WINDOWS\system32>npm install -g react-native-cli // to install RN CLI
5] Create workspace of your RN projects
- D:\ReactNative>react-native init projectname //it will generate project inside mentioned path.
6] setup environment variable
set up new variable under user variable (if not exist) JAVA_HOME with the value
C:\Program Files\Java\jdk-10.0.2 (your JDK path)
set up new variable under user variable (if not exist) Path with the value
C:\Users\Admin\AppData\Local\Android\sdk\platform-tools //your sdk platform tools path
7] run your project using following command inside CMD
D:\ReactNative>react-native run android

How to Fix Build Failed on React-Native run-android?

So I'm getting this error
~/projects/personal-projects/react/myapp ⌚ 18:12:24
$ react-native run-android --variant=release
Scanning folders for symlinks in /Users/user/projects/personal-projects/react/myapp/node_modules (22ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installRelease)...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 14.706 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
I already have my android sdk installed and I also have java installed.
this is what is in my .bach_profile
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
export JAVA_HOME=$Home/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home
I've tried adding a local.properties file and added sdk.dir pointing to my Android/sdk folder. But still this error persists. How do I fix this?
Please make file local.properties in folder android then add the following line on file
sdk.dir=/Users/apple/Library/Android/sdk(Please add your sdk path here)
You need to add ANDROID_HOME, JAVA_HOME variables in environmental variables and
tools and platform-tools in path of system to run android apk.
Setting ANDROID_HOME variable in environmental variables.
Setting JAVA_HOME variable in environmental variables.
So the solution to my problem was:
1) add my ANDROID_HOME and JAVA_HOME paths in my .bash_profile
Solution by #rana_sadam
2) Create local.properties and add sdk.dir=<PATH TO ANDROID SDK> inside the android folder.
Solution by #nisarg Thakkar

Failed to notify project evaluation listener > javax/xml/bind/annotation/XmlSchema

I trying to first run an react-native app with react-native run-android. I expect it to work, like it does when I call react-native run-ios.
Have a lot of users with same kind of error here on stack, "Failed to notify project evaluation listener".
Observed Behavior
> react-native run-android
Scanning folders for symlinks in /Users/tiagogouvea/www/go-along/mobile/node_modules (12ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.gradle.internal.reflect.JavaMethod (file:/Users/tiagogouvea/.gradle/wrapper/dists/gradle-4.0-milestone-1-all/2rnr7rhi2zsmkxo9re7615fy6/gradle-4.0-milestone-1/lib/gradle-base-services-4.0.jar) to method java.lang.ClassLoader.getPackages()
WARNING: Please consider reporting this to the maintainers of org.gradle.internal.reflect.JavaMethod
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to /Users/tiagogouvea/Library/Android/sdk/ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
> javax/xml/bind/annotation/XmlSchema
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED in 4s
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
Environment
npm ls react-native-scripts: empty
npm ls react-native: react-native#0.50.3
npm ls expo: empty
node -v: v8.0.0
npm -v: 5.5.1
yarn --version: 1.2.1
watchman version: 4.9.0
Operating system: macOs 10.12.6
Phone/emulator/simulator & version: Genymotion image
As mentioned in a comment to the bug filed by OP, Gradle seems to have issues with Java 9 or later.
You need to install JDK 8 (JRE is not enough, and versions later than 8 will not work) and tell Gradle to use it, not the default Java version on your system.
In my case (running Ubuntu 18.04), this required installing openjdk-8-jdk (I already had JDK 11 and JRE 8 but not JDK 8).
You have several ways of telling Gradle to use JDK 8 (in all examples, replace the path with the actual path to your JDK installation; the one shown here is valid for Ubuntu 18.04 amd64):
Run Gradle with the option
-Dorg.gradle.java.home=/usr/lib/jvm/java-8-openjdk-amd64
Ensure ~/.gradle/gradle.properties contains the line
org.gradle.java.home=/usr/lib/jvm/java-8-openjdk-amd64
In your build.gradle include the following lines:
compileJava.options.fork = true
compileJava.options.forkOptions.executable = /usr/lib/jvm/java-8-openjdk-amd64
That has helped me get rid of the same error on a different project.
In fact I was running Java 9, running a java --version gave me:
$: java --version
java 9
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
To solve it completely I did:
1) Removed Java 9:
sudo rm -rf "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin"
sudo rm -rf "/Library/PreferencePanes/JavaControlPanel.prefPane"
sudo rm -rf "~/Library/Application Support/Java"
2) Installed back Java 8 - download here
3) Added JAVA_HOME line to my bashfile (~/.bash_profile):
nano ~/.bash_profile
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
* Pay attention to use right jdk version on path
And, everything wokrs fine now. Thanks for help #user149408!
I've resolved this issue by cleaning all the Gradle cache, stoping the Gradle Daemon process, and created a new build successfully using the following command. Make sure your current directory is android.
rm -rf ~/.gradle/caches && ./gradlew --stop && ./gradlew cleanBuildCache && ./gradlew bundleRelease

Updated Android_HOME variable Ionic Issue

There is an issue with the path. Android Studio SDK is present in my D drive. When I execute the build command I get the following error
"Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.
Looked here: C:\Users\Max\AppData\Local\Android\sdk\tools\templates\gradle\wrapper"
Actual SDK location is in
"D:\Users\Max\AppData\Local\Android\sdk\tools\templates\gradle\wrapper". What should I change in Ionic app such that it looks for SDK in D drive?
Here is the Log
C:\Users\Max\Desktop\Gre\demo\demoApp>ionic build android
Running command: "C:\Program Files\nodejs\node.exe" C:\Users\Max\Desktop\Gre\demo\demoApp\hooks\after_prepare\010_add_platform_class.js C:\Users\Max\Desktop\Gre\demo\demoApp
add to body class: platform-android
ANDROID_HOME=C:\Users\Max\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\java\jdk1.8.0_121
Subproject Path: CordovaLib
Where:
Script 'C:\Users\Max\Desktop\Gre\demo\demoApp\platforms\android\CordovaLib\cordova.gradle' line: 64
What went wrong:
A problem occurred evaluating root project 'android'.
No installed build tools found. Install the Android build tools version 19.1.0 or higher.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Home to update the ANDROID_HOME variable?
Unzip -> copy and paste "tools" >only "templates" folder to your project folder (/Libraries/Android/sdk/tools/)
Example: C:\Users\yourUsers\AppData\Local\Android\sdk\tools
Link http://tools.android.com/recent/androidsdktoolsrevision2530feb2017
Get just the command line tools here : https://developer.android.com/studio/index.html#downloads
Next unzip, copy/paste 'templates' folder in '.../Android/sdk/tools/'

Categories

Resources