React-native installation issue - android

Followed the setup steps from official site,I am not able to find react-natve command refer below console commands and its output:
Bhushans-MBP:node_modules bhushanraut$ npm install -g react-native-cli
/Users/bhushanraut/.npm-packages/bin/react-native -> /Users/bhushanraut/.npm-packages/lib/node_modules/react-native-cli/index.js
/Users/bhushanraut/.npm-packages/lib
└── react-native-cli#1.2.0
Bhushans-MBP:node_modules bhushanraut$ react-native init AwesomeProject
-bash: react-native: command not found
Please help me to resolve this.Thanks in advance.

The issue is /Users/bhushanraut/.npm-packages/bin/ directory is not added to global PATH variable.
You need add that to PATH variable.
Execute the below command in terminal
vi ~/.bash_profile
This will open the file in vi editor. Append the following line in that file.
export PATH=$PATH:'/Users/bhushanraut/.npm-packages/bin/'
Then save and close the file.
Execute the following command
source ~/.bash_profile
Now try executing react-native init AwesomeProject command. This should solve the problem.

The below steps may be useful for react-native installation if you encounter any problem
Steps followed from the below URL
https://shift.infinite.red/getting-started-with-react-native-development-on-windows-90d85a72ae65
npm install -g react-native-cli
react-native init AwesomeProject
cd AwesomeProject/
((if not exist "%USERPROFILE%/.gradle" mkdir "%USERPROFILE%/.gradle") && (echo org.gradle.daemon=true >> "%USERPROFILE%/.gradle/gradle.properties"))
react-native run-android
There was error unable to configure the gradle from #react-native-community/CLI-Platform-android
Hence navigate to AwesomeProject/node_modules, run the below command
npm i #react-native-community/cli-platform-android
Finally build is executed successfully without any error
react-native run-android
In another command prompt start the emulator
C:\Users\tapzu\AppData\Local\Android\Sdk\emulator>emulator -list-avds
Nexus_6P_API_28
C:\Users\tapzu\AppData\Local\Android\Sdk\emulator>emulator -avd Nexus_6P_API_28

Related

Trying to build react native app for Android on Mac M1 - Error: No emulators found as an output of `emulator -list-avds`

I have installed Android Studio on my mac M1
I have added a virtual device in Android Studio using Device Manager
The app builds fine from inside Android Studio......however when I run npx react-native run-android from command line in VSCode, I get the error No emulators found as an output of emulator -list-avds
However when I navigate to emulator folder using cd ~/Library/Android/sdk/emulator and run command ./emulator -avd {AVD_NAME}, the emulator starts fine.....however even with the emulator running, the command npx react-native run-android still gives the error No emulators found as an output of emulator -list-avds
UPDATE 04/26 - I followed instructions from #qqNade, however I am still getting same error...see screenshot below:
Just noticed from the screenshot above, the error
/bin/sh: adb: command not found
..also, when I run echo $PATH in terminal, I get the following response:
/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
I dont see any reference to android in there, so I assume thats not a good thing
UPDATE 04/26 #2
I added a ~/.zshrc file and populated it as per below:
export ANDROID_HOME="$HOME/Library/Android/sdk"
export
PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
..that solved the /bin/sh: adb: command not found error, but now I have a new one:
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
at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
at onErrorNT (node:internal/child_process:476:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
....at least its launching the emulator now
UPDATE 04/26 #3
A number of SO posts told me to run the following command from android folder (and then clean)
chmod +x gradlew;
...now Im getting a different error:
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
./gradlew: line 188: syntax error: unexpected end of file
Im wondering if this has anything to do with fact that I created the app originally on Windows.....and this is the first time Im trying to build on Mac?
I checked gradlew file in VSCode and its showing as LF (not CRLF) which as I understand it is correct when building for Mac
I also faced such a problem, to solve it you need to open a command prompt and enter
nano ~/.zsh_profile
after which you need to add this to the file and save
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
then enter on the command line
source $HOME/.zsh_profile
I want to help you.
You're in the home directory (you can go there with cd $HOME or cd ~)
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
source ~/.bash_profile (or source ~/.zshrc, take a look at my note at the end please)
After that, when you execute command vi .bash_profile (or vi .zshrc), you should see something like that
At this point, you can try to execute emulator -list-avds command again
And yes, echo $PATH should show you entries related with Android like ~/Library/Android/sdk/platform-tools
echo $ANDROID_HOME as well
If still not working, I would try to navigate to android folder and run the commands below one more time
chmod +x gradlew
./gradlew clean
react-native run-android
NOTE: Please be sure which shell your mac is using with the command below.
echo $0
Further reading
setting up development environment
I have used homebrew for setting up
echo $PATH
/bin:/usr/bin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/userName/Library/Android/sdk/emulator:/Users/userName/Library/Android/sdk/platform-tools
when we get this 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
at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
at onErrorNT (node:internal/child_process:476:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
try running this command and it will update the gradlew file with access permission, this is for M1 chip machine only
cd android
chmod +x gradlew
This solved my issue

React native command not found

I am starting to install react native. I had successfully installed homebrew, nodejs , npm. but not able to install react native
First I had tried
npm install -g react-native-cli
gives me write warning:
Missing write access to /Users/project/.npm-packages/lib/node_modules/react-native-cli
After that I had tried
sudo npm install -g react-native-cli
/Users/project/.npm-packages/bin/react-native -> /Users/project/.npm-packages/lib/node_modules/react-native-cli/index.js
/Users/project/.npm-packages/lib
└── react-native-cli#1.0.0
Looks like install.
After that I tried
react-native init AwesomeProject
Error : react-native: command not found
What could be the problem
First of all, you have to install react native globally
npm install -g react-native-cli
then it will show you the path for the react native like the following
/Users/{yourUser}/.npm-packages/bin/react-native -> /Users/{yourUser}/.npm-packages/lib/node_modules/react-native-cli/index.js
Then you have to set the default path from the above result and execute the following command
export PATH="/Users/{yourUser}/.npm-packages/bin/:$PATH"
Then reload you session/env vairables
source ~/.bash_profile
It will work like charm!
Make sure that /usr/local/share/npm/bin is in your PATH to use binaries installed with npm
Add the following line to your ~/.bashrc
export PATH="/usr/local/share/npm/bin:$PATH"
Then reload your shell session and try that again
sudo yarn global add expo-cli
sudo yarn global add react-native-cli
You must use sudo here.
when you are using the latest version of node js and others related to react native
they updated to run react native app
npx react-native run-android
npx react-native run-ios
You can check Here

react-native run-android is unrecognized

I've installed react-native-cli globally:
npm install -g react-native-cli
Then run:
react-native init AwesomeProject
cd AwesomeProject
I got the following structure:
-- AwesomeProject
---- node_modules
------ react-native
When I run react-native run-android I get an error:
Command run-android unrecognized. Did you mean to run this inside a react-native project?
When I run react-native start I get the same.
react-native -v
prints:
react-native-cli: 0.2.0
react-native: n/a - not inside a React Native project directory
What I'm doing wrong?
the answer is easy nad it is not because of any bug at all.
make sure you are in correct directory
if in current directory there is not any react native app ,it gives you this error
What caused this for me was running npm install --save [package] when actually the system has previously been using yarn instead of npm.
To solve this I just deleted the node_modules folder and ran: yarn install and after that react-native run-ios (or android) works fine.
(This is a duplicate of React Native: Command `run-ios` unrecognized)
I just ran "yarn" with no arguments and it fixed it.
Please try this command:
npm install --save react-native
The problem was that I terminated init command because it looked like hanged without errors (even 24 hours later). To fix this I updated nodejs and npm to newer versions. Once I have done it react-native init was executed properly and there is no more problem with react-native run-android.
react-native run-android is unrecognized
Make sure that you have installed npm or use
in your project directory
npm install
you have to update your npm.
To do that
npm install npm#latest -g
try "yarn install".
It will install the missing files in node_modules
It worked for me
This can be caused by a couple of issues.
!!! Before trying each solution remember to open a new terminal since you might have old paths sources from your .bashrc file. !!!
You did not install the contents of the project. In order to solve this you have to install the node_modules by typing:
npm install or yarn install
You are coming back to a previously installed project after doing some funny things with your react-native installation and global configurations. (Upgrading the library, upgrading node doing something with globally installed node_modules).
You should clean all your caches and project modules
Here you can find a command to do all these things in one line (remember to replace npm with yarn accordingly):
https://gist.github.com/jarretmoses/c2e4786fd342b3444f3bc6beff32098d
Your global installation of react-native or react-native-cli is broken. In this case simply reinstall your libraries globally.
npm: npm install -g react-native && npm install -g #react-native-community/cli
yarn: yarn global add react-native && yarn global add #react-native-community/cli
I think the command you are looking for is react-native run-android.
cd into your project and run this command where all you js files are present and not in the android folder.
It will run a package manager, do not close that. Also you need to have an emulator or a device connected to your computer with usb debugging enabled.
Hope the answer helped
npx react-native run-android
Use of npx will pick local npm node_modules directory
Do npm install then run react-native run-android
Make sure you go into the directory having package.json
If you have deleted nodemodules try "npm install".
And don't forget the "init" in "react-native init MyApp". "init"
initializes the package.json.
Step 01 : Make sure that you are in right directory
Step 02 : npm install run this command
Step 03 : npm audit fix run this to fix issues
Try deleting node_modules folder and then run the commands again
You can solve this by yarn or npx:
yarn react-native run-android
npx react-native run-android
Everything has already tried like me? Then try again once "Yarn install after deleting node_modules". It worked for me.
I did everything correct while setting up, but was unable to run the android code. Just make sure while running the command react-native run-android that, you are inside the AwesomeProject folder created by the react-native init AwesomeProject command.
The folder by default for my PC was under C:\Windows\system32\AwesomeProject in Windows.
Hope it helped for the first timers :)
You need to update the project with the latest version of react-native. Just run this command.
npm install --save react-native#latest
If you guys have latest react native version and facing this error
"UNRECOGNIZED COMMAND run-android".
then run follow these steps it will definitely help you.
Step: 1 -> create a new file "react-native.config.js" in the project root directory.
Step : 2 -> Inside "package.json" you have "assets" array inside "rnpm" object cut these assets from this and paste in your "react-native.config.js".
i-e:
module.exports = {
assets: ['./assets/fonts'],
}
Step : 3 -> Remove "rnpm" object from "package.json".
Step : 4 -> Replace your "scripts" with below mentioned "scripts" inside "package.json"
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"android": "react-native run-android",
"ios": "react-native run-ios",
"lint": "eslint .",
"android:prod": "npx react-native run-android --variant=release",
"ios:prod": "react-native run-ios --configuration Release"
}
That's it
Happy Hacking..............
Uninstall react-native from global
$ npm uninstall -g react-native
Then
Install react-native to global
$ npm install -g react-native-cli
That worked for me
react-native run-android
start [options] starts the webserver
run-ios [options] builds your app and starts it on iOS simulator
run-android [options] builds your app and starts it on a connected Android emulator or device
new-library [options] generates a native library bridge
bundle [options] builds the javascript bundle for offline use
unbundle [options] builds javascript as "unbundle" for offline use
eject [options] Re-create the iOS and Android folders and native code
link [options] [packageName] links all native dependencies (updates native build files)
unlink [options] <packageName> unlink native dependency
install [options] <packageName> install and link native dependencies
uninstall [options] <packageName> uninstall and unlink native dependencies
upgrade [options] upgrade your app's template files to the latest version; run this after updating the react-native version in your package.json and running npm install
log-android [options] starts adb logcat
log-ios [options] starts iOS device syslog tail
dependencies [options] lists dependencies
info [options] Get relevant version info about OS, toolchain and libraries
They have made some unnoticeable changes. For instance run-android(now) run android(before).
Try to delete "package-lock.json" and re-run "npm install", then try your command, It should work
I got this error because I had parenthesis in the path "(" and ")". Possibly this error is thrown for other special characters as well.
Ensure you run the command in the projects' terminal, preferably the Android IDE. Run the adb devices to know your active devices as well
If your package.json file is containing any comment then this error is comes. So remove all comments from package.json and then run command it will work.
Also try to run command npm install --save then it will log if other error there. If any others error also there, then first fix it and then run command it will work.
In Android Studio click in Tools -> SDK Manager -> in System Settings click in Android SDK -> choose tab SDK Tools, then enable Android SDK command line tools (lasted).
It work for me!
Open your React Native Project Root Directory and locate android -> app -> build -> intermediates -> signing_config -> debug -> out -> signing-config.json
Delete signing-config.json file
And rebuild your application.
react-native run-android
First thing you need to delete node_mouldes and package.lock.json and do yarn install after that if you're using Windows OS you need to use PowerShell not git bash and write this command "react-native run-android"
Install npm again to latest
react-native init project_name
cd project_name
open android studio the same android folder inside your project_name
react_native run_android
will work now
for the last time your project was working fine and now you got this error suddenly and you have Node modules already installed then just trynpm install --save react-native
this work for me

react-native: command not found

I am getting -bash: react-native: command not found error while creating a react-native project.
Below are the additional info
1. brew --version
homebrew 0.9.9
2 brew info watchman
watchman `enter code here`stable 4.50
/usr/local/Cellar/watchman/4.4.0
3. brew info flow
stable 0.24.1
/usr/local/Cellar/flow/0.24.1
4. brew info node
stable 6.1.0
/usr/local/Cellar/node/6.1.0
5. npm -version
3.8.6
6. echo $PATH
/Users/Ashok/.rbenv/shims:/Users/Ashok/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I tried the suggested steps from this link but I am still getting the same error.
I don't have any "npm" directory which they have specified in the solution
Ashoks-MacBook-Pro:share Ashok$ ls
aclocal doc info ruby-build zsh
autoconf emacs man systemtap
But I found npm file exists in the below location.
/usr/local/Cellar/node/6.1.0/etc/bash_completion.d
I uninstalled react-native and installed it again but I am still facing the same issue.
After adding right path to the PATH variable issue is resolved.
Below are the steps to find the right path.
1. Enter: npm install -g react-native-cli
output: /usr/local/Cellar/node/6.1.0/libexec/npm/bin/react-native ->/usr/local/Cellar/node/6.1.0/libexec/npm/lib/node_modules/react-native-cli/index.js/usr/local/Cellar/node/6.1.0/libexec/npm/lib
└── react-native-cli#0.2.0
from above output you can clearly see the path: /usr/local/Cellar/node/6.1.0/libexec/npm/bin/react-native
export PATH="/usr/local/Cellar/node/6.1.0/libexec/npm/bin:$PATH"
react-native init appName
cd appName
react-native run-ios
if you getting xcrun: error: unable to find utility "simctl" at this stage you can reslove using below steps
XCode -> Preferences -> Locations -> Command Line Tools -> Choose Xcode 7.2.1
You can find original solution from xcrun unable to find simctl
Thanks to #fbozo
That's It!!!
run this code
npm i -g react-native-cli
close your cmd and open it again
After continually running into this problem, and hitting this answer and not having it work..
Assuming you don't run npm as root/sudo (which you shouldn't do!) your npm modules will be installed in whatever you set your default directory to be.
Assuming you have followed those instructions, and your default directory is ~/.npm-global, then you need to add ~/.npm-global/bin to your path.
This is outlined in those instructions, but for me I added this to .bashrc:
export PATH=$PATH:$HOME/.npm-global/bin
Then restart your shell and it will work.
Try
npx react-native
if doesn't work install globally
npm i -g react-native-cli
If who have error , try it with sudo:
sudo npm install -g react-native-cli
If you're using yarn, you may have to run commands with yarn in front. Example:
yarn react-native info
I ran into this issue by being a bit silly. I use nvm to manage my different versions of node, and installed react-native into a version of node that was not my default. Upon opening a new shell, I lost my command. :) Switching back of course fixed things.
If for some strange reasons, the path to react-native is not in the PATH, you should take note where the react-native executable is installed. Generally, the issue with command not found is because they are not in PATH.
For example, I use nodenv and run npm install -g react-native
/Users/khoa/.nodenv/versions/10.10.0/bin/react-native -> /Users/khoa/.nodenv/versions/10.10.0/lib/node_modules/react-native/local-cli/wrong-react-native.js
So I need to add that to my PATH
export PATH=$HOME/.nodenv/versions/10.10.0/bin:$PATH
You can verify with echo $PATH
Or you can use npx to execute local npm modules, for example
npx react-native run-ios --simulator='iPhone X'
Install react-native globally by using the following command
npm i -g react-native-cli
Had the same issue but half of your approach didn't work for me .
i took the path the way you did :from the output of react-native-cli instal but then manually wrote in ect/pathes with:
sudo nano /etc/paths
at the end i've added the path from output then ctrl x and y to save .
Only this way worked but big thanks for the clue!
Install react-native-cli with npm install -g react-native-cli.
You may need to use sudo like sudo npm install -g react-native-cli
At first run this command on your terminal.
npm i -g react-native-cli
Then create your react-native project by this command.
React-native init Project name
then move to your project directory by cd command.
According to official documentation, the following command worked for me.
npx react-native run-android
Link is here
https://facebook.github.io/react-native/docs/getting-started
I was trying to run by "react-native run-android" command. make sure to have react-native cli installed globally!
In case anyone has this problem, I had a similar problem to qix, but more nuanced.
New shell terminals would default to a different version of node.
I would change my terminal to the node I wanted, but when the bundle script run, it ran in a new shell, and it got the default version which did not have react-native installed.
I used nvm alias default x.x.x so that new shells would inherit the default version I wanted.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install yarn
brew install node
brew install watchman
brew tap AdoptOpenJDK/openjdk
brew cask install adoptopenjdk8
npm install -g react-native-cli
Dears,
Please try : npm install -g react-native-cli
If you get an error like Cannot find module ‘npmlog’ you can install npm directly using this command. If the above command run successfully then no need to run this command
curl -0 -L https://npmjs.org/install.sh | sudo sh
#For_Ubuntu.
Best regards.
In cmd Administration mode,Run
npm install react-native-cli
This is really weird, on my side (macOS 10.14), i'm pretty sure my node and npm work but i kept getting command not found only for this particular package. I ended up doing the following:
Install react-native-debugger
Make sure you enabled remote JS debugging, docs
Run react-native-debugger
Run your RN app
You can now debug view hierarchy and see console logs in react-native-debugger
I already had react-native and react-native-cli installed and just had to run:
yarn install
I had this issue after ejecting from expo and forgot to delete the node_modules and reinstall by running yarn or npm install.
After I did that then run npx react-native run-android, it worked fine!
try using react-native --help and see what comes up. try curl
react native library recommendation:
If you get an error like Cannot find module 'npmlog', try installing npm directly: curl -0 -L https://npmjs.org/install.sh | sudo sh.
https://facebook.github.io/react-native/docs/getting-started.html
I did an npm update, runned into the same error but after do an npm install and re-build the app worked!

Failed to find 'ANDROID_HOME' and 'android' while running ionic

I am getting following error when I am running sudo ionic build android
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 unzipped android-sdk inside '/opt'.android command runs fine from terminal.
I am setting my $ANDROID_HOME in ~/.bashrc
export ANDROID_HOME="/opt"
export PATH=$PATH:$ANDROID_HOME
export PATH=$PATH:/opt/platform-tools
export PATH=$PATH:/opt/tools
echo $ANDROID_HOME gives /opt.
echo $PATH gives /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/arvind/workspace:/opt:/opt/platform-tools:/opt/tools
P.S.: Running android from terminal gives following warning.( Don't know if it matters ).
(Android SDK Manager:6041): IBUS-WARNING **: The owner of /home/user1/.config/ibus/bus is not root!
If you have installed ionic globally(use sudo npm install -g ionic), you should not add sudo when you use ionic cli command. Just use:
ionic platform rm android
ionic platform add android
ionic build android
Hope this will help you, regards!
you just have to point out the bin directory inside android studio as:
inside ~/.bashrc
export ANDROID_HOME=/path/to/android-studio/
export PATH=$PATH:$ANDROID_HOME/bin
now echo $PATH and make sure the android studio is included in the path.

Categories

Resources