ERROR: JAVA_HOME is not set and no java command could be found in your PATH react native

 

时间:2019-06-01 13:03   分类:学习   标签:react-native

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. error 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: //facebook.github.io/react-native/docs/getting-started.html error Command failed: gradlew.bat app:installDebug. Run CLI with --verbose flag for more details.

运行react-native时候出现这个问题,

先检查是否已安装java jdk

并以配置好环境变量

git里下载://github.com/frekele/oracle-java/releases

不要去官网下载,速度慢成狗

配置环境变量

以win10为例

桌面》电脑》右击属性》高级系统设置》环境变量》系统变量

下面框里,我是已经添加好了

点击新建

变量名:JAVA_HOME

路径:根据自己安装目录

然后确定

在然后呢编辑path那个变量

先删除第一个,oracle/java之类的路径,java默认设置的

或者不删除,直接编辑,改成%JAVA_HOME%\bin,这个也行,

否则

点击新建

输入%JAVA_HOME%\bin

最后,确定,就行

记得重新打开cmd窗口,否则java还是没有找到

在运行react-native就成功了

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: //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:

  1. How could I find the internal Java inside the Android Studio folder so that I could point JAVA_HOME to it?
  2. 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?

0

ventanas 10:

Android Studio -> Archivo -> Otras configuraciones -> Estructura de proyecto predeterminada... -> Ubicación de JDK:

copie la cadena que se muestra, como:

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

En la ventana del directorio del localizador de archivos, haga clic derecho en "Esta PC" ->

Propiedades -> Configuración avanzada del sistema -> Variables de entorno... -> Variables del sistema

haga clic en el botón Nuevo... debajo de Variables del sistema, luego escriba y pegue respectivamente:

.......Nombre de la variable: JAVA_HOME

.......Valor de la variable: C:\Program Files\Android\Android Studio\jre

y presione los botones OK para cerrar.

Algunas instalaciones pueden requerir que JRE_HOME también esté configurado, de la misma manera.

Para verificar, abra una NUEVA ventana de consola negra, luego escriba echo %JAVA_HOME% . Debería recuperar la ruta completa que escribió en la variable del sistema. Windows 10 parece admitir muy bien los espacios en las rutas de los nombres de archivo para las variables del sistema, y no parece necesitar ~tilde eliding.

4 months ago · Santiago Trujillo Report

0

Responderé mis propias preguntas y responderé a mis compañeros usuarios de Linux:

1- Para apuntar JAVA_HOME al JRE incluido con Android Studio, primero ubique la carpeta de instalación de Android Studio, luego busque el directorio /jre . La ruta completa de ese directorio es lo que necesita para configurar JAVA_PATH (gracias a @TentenPonce por su respuesta ). En Linux, puede configurar JAVA_HOME agregando esta línea a sus archivos .bashrc o .bash_profile files :

export JAVA_HOME=<Your Android Studio path here>/jre

Este archivo (uno u otro) es el mismo al que agregaste ANDROID_HOME si estabas siguiendo React Native Getting Started para Linux. Ambos están ocultos de forma predeterminada y se pueden encontrar en su directorio de inicio. Después de agregar la línea, debe volver a cargar el terminal para que pueda recoger la nueva variable de entorno. Así que escribe:

source $HOME/.bash_profile

o

source $HOME/.bashrc

y ahora puedes ejecutar react-native run-android en esa misma terminal. Otra opción es reiniciar el sistema operativo. Otros terminales pueden funcionar de manera diferente.

NOTA: para que el proyecto se ejecute realmente, debe iniciar un emulador de Android con anticipación o tener un dispositivo real conectado. La forma más fácil es abrir un proyecto de Android Studio ya existente e iniciar el emulador desde allí, luego cerrar Android Studio.

2- Dado que lo que parece hacer react-native run-android es solo esto:

cd android && ./gradlew installDebug

De hecho, puede abrir el proyecto de Android anidado con Android Studio y ejecutarlo manualmente. Los cambios de JS se pueden volver a cargar si habilita la recarga en vivo en el emulador. Escriba CTRL + M (CMD + M en MacOS) y seleccione la opción "Habilitar recarga en vivo" en el menú que aparece (Felicitaciones a @BKO por su respuesta )

4 months ago · Santiago Trujillo Report

0

Creo que la forma correcta de encontrar el Java interno utilizado por Android Studio es

  1. Abra el estudio de Android
  2. Vaya a Archivo->Otras configuraciones->Estructura de proyecto predeterminada/Ubicación de JDK:
  3. y copie cualquier cadena que se especifique allí

Esto no requerirá memorizar la carpeta o buscar Java y también estos pasos tomarán en cuenta cualquier cambio futuro en la ubicación de Java por parte del equipo de Android Studio, supongo.

4 months ago · Santiago Trujillo Report

How do you fix error JAVA_HOME is not set and no Java command could be found in your path?

Solution 1.
Just open your terminal..
Run this command flutter config –android-studio-dir='<path to android studio>.
flutter doctor..
Thats It..

How do you fix please set the JAVA_HOME variable in your environment to match the location of your Java installation?

To set JAVA_HOME, do the following: Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1.

What happens if JAVA_HOME is not set?

If any program that requires a Java runtime fails to find the JAVA_HOME environment variable upon startup, or if the JAVA_HOME environment variable is misconfigured, it will result in some of the following error messages to be displayed: A Java installation exists but JAVA_HOME has been set incorrectly.

How do I set Java path in Windows 10?

Procedure.
Download or save the appropriate JDK version for Windows. ... .
Right-click the Computer icon on your desktop and select Properties..
Click Advanced system settings..
Click Environment variables..
Under User variables, click New..
Enter JAVA_HOME as the variable name..
Enter the path to the JDK as the variable value..

Toplist

Neuester Beitrag

Stichworte