I've followed step by step the official Getting Started. I started from a clean linux install and installed everything required as per the "Building Projects with Native Code" tab. I have also read the troubleshooting section. I've already created the project using the terminal.
This is the error when I run react-native run-android:
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
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
It does not find JAVA_HOME because the latest versions of Android Studio don't require Java to be installed in the system. Instead an internal JRE is used.
Duplicate disclaimer: I've already read this question. This is not what I want. I know how to set the Java home. I just want to run the react project WITHOUT having to install a separate Java.
Questions:
How could I find the internal Java inside the Android Studio folder so that I could point JAVA_HOME to it?
If not possible, could I open and run the project inside the android folder with Android Studio? How would I refresh this project after modifying the React JavaScript code in the parent folder?
Windows 10:
Android Studio -> File -> Other Settings -> Default Project Structure... -> JDK location:
copy string is shown, such as:
C:\Program Files\Android\Android Studio\jre
In the file locator directory window, right-click on "This PC" ->
Properties -> Advanced System Settings -> Environment Variables... -> System Variables
click on the New... button under System Variables, then type and paste respectively:
.......Variable name: JAVA_HOME
.......Variable value: C:\Program Files\Android\Android Studio\jre
and hit the OK buttons to close out.
Some installations may also require JRE_HOME to be set in the same way.
To check, open a NEW black console window, then type echo %JAVA_HOME%. You should get back the full path you typed into the system variable. Windows 10 supports spaces in the filename paths for system variables very well and does not need ~tilde eliding.
I'll answer my own questions and sponfeed my fellow linux users:
1- To point JAVA_HOME to the JRE included with Android Studio first locate the Android Studio installation folder, then find the /jre directory. That directory's full path is what you need to set JAVA_PATH to (thanks to #TentenPonce for his answer).
On linux, you can set JAVA_HOME by adding this line to your .bashrc or .bash_profile files:
export JAVA_HOME=<Your Android Studio path here>/jre
This file (one or the other) is the same as the one you added ANDROID_HOME to if you were following the React Native Getting Started for Linux. Both are hidden by default and can be found in your home directory. After adding the line you need to reload the terminal so that it can pick up the new environment variable. So type:
source $HOME/.bash_profile
or
source $HOME/.bashrc
and now you can run react-native run-android in that same terminal. Another option is to restart the OS. Other terminals might work differently.
NOTE: for the project to actually run, you need to start an Android emulator in advance, or have a real device connected. The easiest way is to open an already existing Android Studio project and launch the emulator from there, then close Android Studio.
2- Since what react-native run-android appears to do is just this:
cd android && ./gradlew installDebug
You can actually open the nested android project with Android Studio and run it manually. JS changes can be reloaded if you enable live reload in the emulator. Type CTRL + M (CMD + M on MacOS) and select the "Enable live reload" option in the menu that appears (Kudos to #BKO for his answer)
I think the right way to find the internal Java used by the Android Studio is to
Open Android Studio
Go to File->Other Settings->Default Project Structure/JDK Location:
and copy what ever string is specified there
This will not require memorising the folder or searching for java and also these steps wil take of any future changes to the java location by the Android Studio team changes I suppose
I'm using Ubuntu 20 on my machine, I have got the same problem the thing that worked for me was:
sudo apt-get install default-jre
you can verify that if the installation was successful or not by:
java --version
you are gonna see something like this in your terminal
openjdk 11.0.12 2021-07-20
OpenJDK Runtime Environment (build 11.0.12+7-Ubuntu-0ubuntu3)
OpenJDK 64-Bit Server VM (build 11.0.12+7-Ubuntu-0ubuntu3, mixed mode, sharing)
It is located on the Android Studio folder itself, on where you installed it.
Please add the JAVA_HOME in the System variable no in the user variable
Create the Variable name as JAVA_HOME
Please use these format in the value box --> C:\Program Files\Java\jdk(version) what you have or downloaded.
I fixed this issue by installing jre, I have jdk already installed but jre was not installed.
For those still not able to set JAVA_HOME from Android Studio installation, for me the path was actually not in C:\...\Android Studio\jre
but rather in the ...\Android Studio\jre\jre.
Don't ask me why though.
Environment variables jre location snippet
For ubuntu 16.0+
You can find the jre folder in android studio on this path /snap/android-studio/current/android-studio/jre
add the following line in your .bashrc or .bash_profile
export JAVA_HOME=/snap/android-studio/current/android-studio/jre
type
sudo nano $HOME/.bashrc
or
sudo nano $HOME/.bash_profile
after this execute the following line to in your terminal where you are executing the npx react-native run-android to reload the terminal with the new changes
source $HOME/.bashrc
or
source $HOME/.bash_profile
All I did is go to my project directory from the cmd (command prompt) I typed java -version.it told me what version it was looking for. so I Installed that version and I changed the path to were the jdk of that version was located .
apparently the system variables were not in sync with the user
variables
run as admin on command prompt and set the variable
i also saw some tips to close the node window and the vscode terminal for
the variable to take effect
tip from this site
https://confluence.atlassian.com/doc/setting-the-java_home-variable-in-windows-8895.html
setx -m JAVA_HOME "C:\Progra~1\Java\jdk1.8.0_XX"
and then
echo %JAVA_HOME%
For fish users:
Open ~/.config/fish/config.fish;
Include line set JAVA_HOME /home/ronald/Documents/android-studio/jre and set PATH $PATH $JAVA_HOME;
Re-open fish terminal.
Welcome :)
After adding the environmental variable , please restart the editor. It may save your ton of time.
Make sure you have java installed
your path is wrong
do this:
export | grep JAVA
THE RESULT: what java home is set to
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
follow the path to see if the directories are correct
i did this in my terminal:
open /Library
then i went to /Java/JavaVirturalMachines
turns out I had the wrong "jdk1.8.0_202.jdk" folder, there was another number...
4. you can use this command to set java_home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
I ran this in the command prompt(have windows 7 os):
JAVA_HOME=C:\Program Files\Android\Android Studio\jre
where what its = to is the path to that jre folder, so anyone's can be different.
what I did to solve this on windows was to go to the environment variables and set the variable name to JAVA_HOME and then set the variable value to C:\Program Files\OpenJDK\openjdk-8u312-b07
then I set the path to C:\Program Files\OpenJDK\openjdk-8u312-b07\bin
From Android Studio, go to File, Settings, "Build, Execution, Deployment", Build Tools, Gradle. You should see the path to your JDK there, as visible in the screenshot (tested on Android Studio version 2020.3.1). Set an environment variable called JAVA_HOME containing that path (just google "set an environment variable" and followed by your Operating System name).
for those who are new to react native development
please set JAVA_HOME like this
instead of
C:\Program Files\Java\jdk1.8.0_301\bin
just remove "\bin" from path
C:\Program Files\Java\jdk1.8.0_301 after removing \bin
Guys after fight a lot to find the solution, including pass for many of that articles. I just realized that when you extract the Android SDK it doesn't come inside the folder cmdline-tools/latest and doesn't matter the place that I put the folder, opt/Androd_SDK, $HOME/Android_SDK the sequence of the error were the same. Until I got this error running:
➜ bin ./sdkmanager -version
Error: Could not determine SDK root.
Error: Either specify it explicitly with --sdk_root= or move this package into its expected location: /cmdline-tools/latest/
So, basic the solution was add the content of the SDK zip inside of the folders cmdline-tools/latest.
Once you do this, SDK and all the commands will work normally. Just don't forget to finish the configuration, like create the environment of the Android SDK, JAVA and so on.
An awesome article is that one:
https://medium.com/#khairold/setting-up-react-native-on-linux-without-android-studio-a65f3e011bbb
;)
if someone still facing similar issue and looking for an answer for the same? I would like to share the solution which worked for me. And by the way I haven't installed JAVA JDK/SDK in order to resolve the issue.
I am using Visual Studio code to develop react-native apps (using nox player for android app testing), I ran into the similar issue:
Issue:
$
› Building app...
$
ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
$
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
C:\Users...\android\gradlew.bat exited with non-zero code: 1
Resolution: In package.json file I have changed "main": "index.js" to "main": "node_modules/expo/AppEntry.js" it worked for me.
It would be great if this solution helps anyone, let me know for any additional information.
Make sure you have installed the following:
Java
JDK
JRE
If you use Ubuntu, maybe its helpful this tutorial. You have solution for how to solve error ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH..
There are many solutions found for Windows or Mac OS on internet to resolve this error. I'm using Ubuntu 22.10 kinetic
Solution:
Go to your Android Studio folder, find folder named jbr, copy all content folder, and if you don't have, create a folder named jre and copy in jre folder, all contents from jbr folder. Case close. Error solved.
java is not set
Video
I get the error message "Error:Specified NDK location does not exists. Please ensure ndk.dir in local.properties file or ANDROID_NDK_HOME is configured correctly." when I try to run a sample android application from ARToolKit in Android Studio 2.2.2. This application has also parts (libraries) written in c++ which is why the NDK is necessary.
I have tried to set the environmental variable ANDROID_NDK_HOME and the property ndk.dir in the local properties file and I still get this message.
I installed the NDK using the built in SDK manager and it was correctly downloaded and installed at the location specified in the variable.
I use a Windows 7 64 bits computer and the target SDK version is 23.
you need to follow the instructions from here: http://artoolkit.org/documentation/doku.php?id=4_Android:android_native
In short:
From the android directory run ./build.sh that is how ARToolKit builds the native libraries for each example project. If you want to use the nativeExamples as well you need to run the ./build_native_examples.sh too.
Also, unfortunately, ARToolKit needs three different environment variables to be set. Two of them need to point to the NDK:
Set ANDROID_HOME to indicate the path to root folder of the downloaded Android SDK.
Set ANDROID_NDK_ROOT to indicate the path to root folder (most likely, “ndk-bundle”) of the downloaded NDK. The ANDROID_HOME environment variable can be used to help define NDK. ANDROID_NDK_ROOT=$ANDROID_HOME/ndk-bundle
Set NDK to the same path as ANDROID_NDK_ROOT. NDK=$ANDROID_NDK_ROOT
Set PATH to include a path to the ndk-build[.cmd] script file, that is, the path to the root folder of the NDK. The NDK environment variable can be used to help define the added path.
Please note that the variable is called ANDROID_NDK_ROOT not ANDROID_NDK_HOME.
Important:
As you are on Windows, you need to use the GitBash to run the *.sh scripts. The Windows command line does not have the commands used in the sh scripts, that is why you need to install and use GitBash.
That should you get going.
There is also the artoolkit.org/community/forum to help you along with questions.
Let me know if that helps.
We decided to use GitHub as our version control. I know the Gradle build scripts use certain paths, such as the Android SDK path in the local.properties file.
Since this path will differ between the five of us, I think the projects will fail to build on my teammates' machines when they pull changes from GitHub. Is this correct?
If so, can we all make an environment variable called something like ANDROID_SDK and use that for the sdk.dir in the local.properties? Would the project properly build on all of our machines if we used the environment variable? Are there any other places where we may need to set
a similar environment variable? Will this work? If so, how do we do this?
I am not sure if this is the best way to go about setting up a team project for Android. I'm looking for suggestions on a best practice for this.
Is this correct?
No, because IMHO local.properties should not be in your Git repo. The standard Android Studio .gitignore file (created when you create the project) has local.properties, meaning that local.properties would not be committed to your repo.
As Doug Stevenson points out in a comment, local.properties is generated when you import a project. It will be driven by Android Studio settings.
can we all make an environment variable called something like ANDROID_SDK and use that for the sdk.dir in the local.properties?
Not for use with Android Studio, at least the last I tried it. For command-line Gradle builds, that works fine, but Android Studio does not pass the environment to its forked Gradle process.
I am having some problems with getting started with my first Cordova app in Visual Studio.
When I create a new Cordova Project, I am presented with a page that says:
We've detected issues with your system's environment configuration
And it lists 3 things that need to be installed:
Android SDK The software is missing from your system. You may also have to configure it after installation. Instructions
Apache Ant The software is missing from your system. You may also have to configure it after installation. Instructions
Git CLI The software is missing from your system. You may also have to configure it after installation. Instructions
I already have the Android SDK installed. So how can I let Visual Studio know where it is? A search for this on Google did not yield any results that were related.
Searching for Git CLI did not yield any results. How do I install this?
I haven't even tried installing Apache Ant yet because I can't get past the other two.
How can I install Git CLI and how do I let VS know where my Android SDK is located?
P.S. I am aware that each of those list items has an 'instructions' link, however, I am unable to access those pages, they say "Webpage is not accessible" in Chrome, Firefox and IE (and Spartan).
I guess you have already installed Tools for Apache Cordova.
Once you did that and you can't install them with the tool, download them manually in their official websites. You can then add the path for these items in :
Tools > Options > Tools for Apache Cordova > Environment Variables
Here is a screen of mine :
I hope it helps
Not sure these are solutions, but something to check for:
If you're using VS2013, ensure you have update 4. Visual Studio Tools for Cordova only relies runs on VS 2013 and 2015.
Of course, ensure you have the latest Tools for Cordova CTP 3.1 (http://www.microsoft.com/en-us/download/details.aspx?id=42675)
In my system path, I have C:\Program Files (x86)\Android\android-sdk\platform-tools. I have ANT_HOME as a system/environment variable set to C:\apache-ant-1.9.3. I have ADT_HOME as a system/environment variable set to C:\Program Files (x86)\Android\android-sdk. I have GIT_HOME set to C:\Program Files (x86)\Git.
Setup your PATH environment variable on Windows
From the Desktop, right-click My Computer and click Properties.
Click Advanced System Settings link in the left column.
In the System Properties window click the Environment Variables button.
Select the PATH variable from the System variables section.
Select the Edit button.
You need to add the path to your Android SDK platform-tools and tools directory. In my example I will use "C:\Development\android-sdk-windows" as the directory the SDK is installed in. Append the following text into the text box:
;C:\Development\android-sdk-windows\platform-tools;C:\Development\android-sdk-windows\tools
Save your edit. Close the Environment Variables dialog.
Additionally, you may need to include %JAVA_HOME%\bin to your PATH as well. To check to see if this is required, run a command prompt and type java. If the program can not be found add %JAVA_HOME%\bin to the PATH. You may need to specify the full path instead of using the %JAVA_HOME% environment variable.
Finally, you may need to include %ANT_HOME%\bin to your PATH as well. To check to see if this is required, run a command prompt and type ant. If the program can not be found add %ANT_HOME%\bin to the PATH. You may need to specify the full path instead of using the %ANT_HOME% environment variable.
I'm trying to build my android app via commandline (batch file to be specific). I'm working on a phonegap/cordova app and I find it to be a bit of an overkill to use Eclipse only for compiling.
If I try it via commandline it works. But if I run it in a batch file it looks like ANT is using JRE instead of JDK??
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre7\lib\tools.jar
If you want to use javac in ant then you need tools.jar to work it properly. You can find this answer on apache ant site (When you need JDK functionality (such as for the javac task or the rmic task), then tools.jar must be added. The scripts supplied with Ant, in the bin directory, will add the required JDK classes automatically, if the JAVA_HOME environment variable is set.).
Not sure why this happens. But you would usually find tools.jar in C:\ProgramFiles\Java\JDK\lib
Copying that to the C:\ProgramFiles\Java\jre\lib folder would make it work without any change to the JAVA_HOME