How to set up and run React Native on your Android Phone
This “tutorial” assumes you already have the Android SDK installed. If you don’t have it, follow this link to set up Android SDK through Android Studio. It’s quite simple.
To install react native on linux you must have node and npm installed.
Let’s start:
Update your PC with
$ sudo apt update
Install open jdk
Do this using the following on the command line
$ sudo apt install openjdk-8-jdk
Create a React Native Project
Using npx
, which ships with Node.js, let's create a new React Native project called "AwesomeProject":
First cd into Desktop
$ cd Desktop
and run
$ npx react-native init AwesomeProject
Add Android Home Environmental Variables
Now go back go to your root directory if you’re not there already by typing
$ cd ~
What we want to do is to open `$HOME/.bash_profile` or `$HOME/.bashrc` to add environmental variables. If you’re using `ZSH`, it should be `$HOME/.zshrc`.
To open `$HOME/.bashrc`, go to the terminal in the home directory and type
$ nano .bashrc
Scroll to the bottom and add these lines of code at the last line
export ANDROID_HOME=$HOME/Android/Sdkexport PATH=$PATH:$ANDROID_HOME/emulatorexport PATH=$PATH:$ANDROID_HOME/toolsexport PATH=$PATH:$ANDROID_HOME/tools/binexport PATH=$PATH:$ANDROID_HOME/platform-tools
When done, Press `ctrl + s` to save and `ctrl + x` to exit.
Next load the config file into your shell by typing the following on the command line
$ source $HOME/.bashrc
If you’re using `ZSH`, it should be `$HOME/.zshrc`
$ source $HOME/.zshrc
Confirm that ANDROID_HOME has been added to your path by typing
$ echo $PATH
You should get this on your screen
/home/user/.nvm/versions/node/v10.16.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/user/Android/Sdk/emulator:/home/user/Android/Sdk/tools:/home/user/Android/Sdk/tools/bin:/home/user/Android/Sdk/platform-tools
Run the react native app
Finally cd into your project which is inside the Desktop directory.
Desktop $ cd AwesomeProject
The next thing is to
- enable USB debugging on your phone, and
- connect your phone to your PC
- or configure emulator and, then run
$ react-native run-android
Start the project
Run
$ yarn start
This will start the project.