JAVA_HOME is not set error, after running React-native app - android

PS C:\Users\Prabhudev\react-projects\react-native\myFirstApp> react-native run-android
info JS server already running.
info Building and installing the app on the device (cd android && gradlew.bat app: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.
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:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: gradlew.bat app:installDebug. Run CLI with --verbose flag for more details.

First Add the JDK and JRE paths to the System Variable "Path"
like below:
Secondly, Add the JAVA JDK path to the USER variable as JAVA_HOME. as shown below:
Restart the cmd and go to the app directory and run the app with react-native run-android
Voila:

Related

Cmd/React Native can't detect my JAVA_HOME environment variables

I'm trying to create a React Native app for Android. I use bash from the command line in Windows 10. I browse to the location of my React Native project and then run "react-native run-android". But then I get an error like this:
$ react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 864 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
/bin/sh: 1: adb: not found
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the 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.
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
at checkExecSyncError (child_process.js:601:13)
at execFileSync (child_process.js:621:13)
at runOnAllDevices (/mnt/c/users/lenovo/documents/repositories/upself rn/upself/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:39)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
TL;DR it tells me to set the environment variable for JAVA_HOME. AFAIK.
The problem is I've already set the JAVA_HOME since I installed the Windows 10 in my laptop which was months ago. I use JDK 12 and have developed few native Android app using Android Studio using this same laptop and never have I encountered any missing JAVA_HOME issue.
This is what I've tried to try to solve this issue:
Run the cmd as administrator
Set the JAVA_HOME to c:\Program Files\Java\jdk-12.0.2\ and the one in Android Studio default SDK location C:\Users\lenovo\AppData\Local\Android\Sdk. Both dont work.
Restart my laptop and cmd (done it multiple times but it still doesnt work).
Put a quotation mark between the path (found this in a stack overflow question).
I've read many questions in stack overflow but none of those works.
So, could anyone help me to solve this problem? Why is it unable to detect the environment path?
According to react native document, you should install just JDK 8 for running react native app
https://facebook.github.io/react-native/docs/getting-started
after installing java and set the environment variable, you must reboot your system.
https://www.thewindowsclub.com/set-java_home-in-windows-10

React-native does not find Genymotion

I installed android studio, I configured the environment variables and everything, I installed genymotion and created a device, but running the react-native run-android in the project folder occurs the following error:
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:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: gradlew.bat app:installDebug. Run CLI with --verbose flag for more details.
please help me in this problem. React-native does not find Genymotion disositivo, in this link has more details: https://pt.stackoverflow.com/questions/382115/react-native-n%C3%A3o-reconhece-genymotion
It tries to connect the emulator to the ADB, by the IP of the device. To check the IP of the device, simply click on an emulator window, the IP address is in the title of the window.
No terminal will run the command:
$ adb connect ip_of_your_emulator:5555
Soon after, run:
$ adb devices
If the name of your file appears in the list, your emulator has been connected successfully!
With the emulator open, simply run the native run-android in the folder of your project.
I've had the same problem earlier this month. As far as I can tell the newer versions of Genymotion don't register on adb devices, a user in the Expo forums speculates it's because they have a paywall now.
I recommend switching to Android Studio, that's what I did to solve my problem.
I ran react-native with the --verbose flag, and got the following error:
...
error Failed to install the app. Make sure you have the Android development
environment set up: https://reactnative.dev/docs/environment-setup.
Error: spawn ./gradlew EACCES
...
So, I gave permissions to the android/gradlew folder as follows:
chmod 755 android/gradlew
But then, I got an error regarding Google Play Licenses:
error Failed to install the app. Please accept all necessary Android SDK
licenses using Android SDK Manager: "$ANDROID_HOME/tools/bin/sdkmanager --licenses".
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
So yeah, pretty the solution was:
Downloading Android Studio with its own SDK
Change the env variabe ANDROID_HOME to the one installed with Android Studio
Installing Google Play Licensing Library (In Android Studio, go to Settings>SDK Manager>SDK Tools, select Google Play License Library and then install)

Reactnative $JAVA_HOME path error

zzz#zzz-PC ~/AndroidStudioProjects/Example $ react-native run-android
Scanning 555 folders for symlinks in /home/zzz/AndroidStudioProjects/Example/node_modules (16ms)
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-9-oracle
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
Anyone can tell what's the problem, after I've run "react-native run-android" command. I've changed my JAVA_HOME path in /etc/environment, it still failed.
You need to be pointing to a jdk, currently you are pointing to a JVM. Go here and download the appropriate jdk and install it. Then switch your JAVA_HOME variable to the new path to the jdk.

sudo ionic run android not working

I am trying to run a hybrid app on my android phone using ionic using the following command:
sudo ionic run android
However I keep receiving this error :
Error: Failed to find 'ANDROID_HOME' environment variable. Try setting
setting it manually. Failed to find 'android' command in your 'PATH'.
Try update your 'PATH' to include path to valid SDK directory.
I have already added platform tools & tools to PATH updated ANDROID_HOME to point to my sdk root.
The ANDROID_HOME environment variable shows up when I run env and the PATH has the tools and platform tools too. Additionally I can execute android too. It launches the SDK Manager as expected.
Details:
ANDROID_HOME: /home/user/Android/Sdk
$PATH: /home/user/Android/Sdk/tools:/home/user/Android/Sdk/platform-tools
Please help! This is driving me up the wall!
Credit for this goes to #heemayl on AskUbuntu.
https://askubuntu.com/a/783805/247116
sudo sanitizes the environment and by default only keeps certain
environment variables available with modifying the values of some
(e.g. PATH).
You can pass the variable ANDROID_HOME manually:
sudo ANDROID_HOME="/actual/path" ionic run android
Or preserve the current environment:
sudo -E ionic run android

Can't execute ionic application in genymotion

I try to execute an application implemented using Ionic within the Genymotion Android emulator.
To create my application, I did the following:
$ ionic start myApp blank
$ ionic platform android
$ ionic run android
Notice that I executed the last command after having started a virtual terminal (Sony Xperia Z for example).
I have the following error:
Running command: /(...)/myApp/hooks/after_prepare/010_add_platform_class.js /(...)/myApp
add to body class: platform-android
Running command: /(...)/myApp/platforms/android/cordova/build
[Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.]
ERROR building one of the platforms: Error: /(...)/myApp/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /(...)/myApp/platforms/android/cordova/build: Command failed with exit code 2
I don't understand why I need to have an ANDROID_HOME set since it's not the thing I want to use...
I installed then an Android SDK and set the ANDROID_HOME environment variable:
export ANDROID_HOME=/home/(...)/android-sdk-linux/
Then I have the following error:
$ ionic run android
Running command: /(...)/myApp/hooks/after_prepare/010_add_platform_class.js /(...)/myApp
add to body class: platform-android
Running command: /(...)/myApp/platforms/android/cordova/run
ERROR: Error: Please install Android target: "android-22".
Hint: Open the SDK manager by running: /home/(...)/android-sdk-linux/tools/android
You will require:
1. "SDK Platform" for android-22
2. "Android SDK Platform-tools (latest)
3. "Android SDK Build-tools" (latest)
ERROR running one or more of the platforms: Error: /(...)/myApp/platforms/android/cordova/run: Command failed with exit code 2
You may not have the required environment or OS to run this project
What isn't clear to me is how to tell Cordova to use Genymotion instead of the default Android emulator...
For information, I installed ionic and cordava like this:
$ sudo npm install ionic -g
$ sudo npm install cordova -g
I'm working on Linux Mint 17 Qiana / Cinnamon 64-bit.
Thanks very much in advance for your help!
Thierry
From the logs it doesn't look like a problem with the emulator/Genymotion but a problem with not having the Android SDK installed. Because of the licenses involved you typically need to install the Android SDK yourself.
This explains the error messages:
It first looks for where the SDK is installed, which is indicated by ANDROID_HOME. It errors since it's initially unset.
Once it's set, it can't find the right SDKs (android-22, platform-tools, tools) since they're not installed.

Categories

Resources