Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i create new react native App using npx?

I didn't use react-native for a few months. It looks like some things have changed meanwhile. In the official documentation they recommend to uninstall react-native-cli and to usenpx react-native init instead. I did this but ended up with an error because I didn't install that package globally. However, if I install react-native globally, it results in an error when I run the project, saying that I should remove the global package.

What is the proper way to create a react app nowadays?

like image 693
Alejandro Quiroz Avatar asked Dec 12 '19 17:12

Alejandro Quiroz


People also ask

What is NPX in react native?

React Native has seen 3 new releases in just past month. Choosing to install react-native globally means that virtually every time a new project is initiated an upgrade has to be handled manually. Instead one might take advantage of the Node Package Executor (NPX) that ships with NPM since version 5.2. 0.


3 Answers

  1. npm uninstall --global react-native-cli
  2. Install node js (i use node js version 12.10.0 here), i dont use the latest one because there is a bug i cant run my react native app
  3. install python2 jdk8 and yarn
  4. install android studio and sdk and add ANDROID_HOME to environment variable
  5. use npx react-native init ProjectName to create new project
  6. use yarn react-native run-android or yarn react-native run-ios to run the project

@Raeygzz if you want to use react-native related command add yarn/npx in the beginning of the command

yarn react-native run-android
yarn react-native run-ios

or

npx react-native run-android
npx react-native run-ios
  1. if you want to create apk debug use in your root project

    cd android && gradlew assembleDebug

  2. apk release in your root project

    cd android && gradlew assembleRelease

  3. Debug with bundle in your root project

    yarn react native run-android

and get the apk file in

android\app\build\outputs\apk\debug

i usually do this if the device i working on doesn't have an usb cable, so i copy the file there, and sent it to the cloud, download it to device and install it, after that i just shake the phone and go to settings and setup debug server ex: 10.xxx.xxx:8081 then run yarn start in cmd shake the device and choose refresh

the difference is here between react-native run-android and gradlew assembleDebug react-native run-android Vs ./gradlew assembleDebug

like image 93
Gus Nando Avatar answered Oct 13 '22 01:10

Gus Nando


Check their official document npx

like image 37
Anuj Sharma Avatar answered Oct 13 '22 01:10

Anuj Sharma


Thanks @Gus Nando for the detail... and if i want to make a debug build for android using npx then what should i follow. And also if there is any changes or change in set of way to create debug as well as production build for both android and ios platform.

Any kind of info related to npx will be of much help. Thanks in advance

like image 39
Raeygzz Avatar answered Oct 13 '22 00:10

Raeygzz