Tterm 'react-native' is not recognized when running react-native run android - react-native

I need help in building my react-native project. I have tried react-native run-android but I get the following error:
react-native : The term 'react-native' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ react-native run android
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (react-native:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Iyayi Kelvin
You will need Node, the React Native command line interface, a JDK, and Android Studio.
I assumed you have,
Development OS: Linux, Target OS: Android
Node
https://nodejs.org/en/download/package-manager/
The React Native CLI
npm install -g react-native-cli
Java Development Kit
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Android development environment
https://developer.android.com/studio/index.html
Watchman (optional)
https://facebook.github.io/watchman/docs/install.html#buildinstall
Creating a new application
$ react-native init AwesomeProject
$ cd AwesomeProject
$ react-native run-android
Note :
if you get an error as follow:
"unable to load scripts from assets 'index.android.bundle' on real device"
Then,
(If not created then) create dir as android/app/src/main/assets
Old react native version below < 0.46
$ react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
or
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
Then,
$ react-native run-android

run this command
npm install -g react-native-cli
after that just add your npm path to your system variables in environment variables
C:\Users\YOUR USERNAME\AppData\Roaming\npm

Related

How To create debug apk file in react native

I have a react native project. it works fine on android. but can not create debug apk file of this project.
first run this command in your terminal
npm run react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
after this go inside your android folder by running this command
cd android && ./gradlew assembleDebug
then you can get your apk from this location
app/build/outputs/apk/debug/app-debug.apk

Unable to load script.Make sure you're either running a Metro server

i stuck with this error when i try npx npx react-native run-android
I got fixed this problem using the below steps.
cd MyApp
I was getting some blacklist.js some character issue. For that I referred this link and replaced sharedBlacklist character set.
(How to resolve the error on 'react-native start')
Next, I ran the below code snippet to address the bundle issue.( Ref Link :
https://medium.com/#adityasingh_32512/solved-unable-to-load-script-from-assets-index-android-bundle-bdc5e3a3d5ff)
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
react-native run-android
Then, it started working.
Hope this helps.

Not able to run on android, while iOS runs fine

I am pretty new to react-native development, I have a project which run properly with iOS simulator, while on android (Emulator and device) it gives Unexpected token '>' error
Try to change "android" folder name to "android-backup"
And run following in the terminal:
$cd MyProjectFolder
$npm start
$react-native start
this work refresh your android project.
also you can clean gradlew with:
$cd android
$gradlew clean
try this
Open Terminal
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
react-native run-android

react-native dosent update any code

my steps:
installed node.js
npm install -g react-native-cli
react-native init AwesomeProject
1.cmd=mkdir android/app/src/main/assets
cmd=react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
react-native run-android (react packager ready and building 100% without any error)
Showing app default index.android.js
after that i close everything and change simple code in index.android.js
run again with react-native run-android (react packager ready and building 100% without any error)
showing me again default index.android.js
why this happening to me ?
Windows 7,real device android 4.2.2 with usb connected

Disabling JS Server from running on react-native run-android command

I perform offline bundling of my react-native project using CMD
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
As bundinling is done offline i dont want JS server to start each time after running the command react-native run-android.
Is there any way out to avoid starting JS server
Internally, react-native run-android starts the packager and run installDebug task on gradlew.
To just run installDebug, on your project root directory run:
cd android && ./gradlew installDebug