Reputation: 603
I'm trying to run my react native app on either an Android Studio emulator or my physical device. I've followed the instructions at https://reactnative.dev/docs/environment-setup under the React Native CLI Quickstart tab, and initialised the 'AwesomeProject' app from that page, but I'm finding the instructions unclear. For instance it says do the following on the command line: npx react-native start
which starts up a process of some sort. Then it says to enter: npx react-native run-android
, but the command line is blocked by the previous process. If I try the latter either in another command prompt or without first running the former command, I get an error Unrecognized command "run-android"
. I should say I have an emulator running from Android Studio before doing all this.
So failing getting it running via the react-native CLI, how do I get it running from within just Android Studio? I've never used Android Studio before, so I have no idea what the process is. Googling hasn't helped either. But as I said, I have managed to get an emulator installed and running.
Any help getting this going either via react-native CLI or from within Android Studio would be greatly appreciated.
edit: I've found how to run my app in Studio, but it pops up an 'Edit configuration' dialogue and says there's no Module selected. But in the module dropdown box there's nothing to select.
Upvotes: 0
Views: 10328
Reputation: 1485
You can try following the below steps:
Make sure that you have 2 environment variables set in your system.
Now execute below commands in command prompt and start you emulator or connect your phone which has development settings ON before this:
npm install
npm install -g react-native && npm install -g @react-native-community/cli
npx react-native init
npx gradlew clean
adb reverse tcp:8083 tcp:8083
. (You need to check the status of your connected devices by executing adb devices
. It will show you the connected devices.)npx react-native bundle --platform android --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --dev false --reset-cache --assets-dest android/app/src/main/res/
npx react-native run-android --port=8083
Upvotes: 3