I wrote a getting started guide for react-native on macOS and for iOS devices few months ago. Now I thought to write it for android devices as well.
Lets get started...
Step 1: Installing Node and Watchman
Official guide suggests to use Homebrew
to install Node
and Watchman
. So first thing first, run this command to install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
After brew is installed, run these commands to install Node
and Watchman
respectively.
brew install node
brew install watchman
Make sure you have 8.3 or newer version of node.
Step 2: Installing Java Development Kit (JDK)
Official guide also recommends to install JDK using Homebrew
. Run this command to get this done.
brew install --cask adoptopenjdk/openjdk/adoptopenjdk8
Make sure you install JDK 8 or newer.
Step 3: Setting up android development environment
Download & Install Android Studio
Download and install Android Studio
here.
Now choose to install "Custom" setup for installation and make sure to select checkboxes of these options.
Android SDK
Android SDK Platform
Performance (Intel ® HAXM)
Android Virtual Device
Then, click "Next" to install all of these components.
Install the Android SDK
To install the SDK, open the android studio. Click on the configure button on bottom right corner of "Welcome to Android Studio" screen. Then select "SDK Manager".
Select the "SDK Platforms" tab from the SDK Manager, then check the box next to "Show Package Details" in the bottom right corner. Expand the Android 9 (Pie) entry, then make sure to check these:
Android SDK Platform 28
Intel x86 Atom_64 System Image or Google APIs Intel x86 Atom System Image
Next, select the "SDK Tools" tab and check the box next to "Show Package Details" here as well. Look for and expand the "Android SDK Build-Tools" entry, then make sure that 28.0.3 is selected.
Finally, click "Apply" to download and install the Android SDK and related build tools.
Configure the ANDROID_HOME environment variable
The React Native tools require some environment variables to be set up in order to build apps with native code.
For this we need to write some code in $HOME/.bash_profile
or $HOME/.bashrc
config file.
To create a new .bash_profile
file, type cd ~/
in your terminal.
Type touch .bash_profile
to create your new file, then type open -e .bash_profile
to open your file and add these lines:
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
Type source $HOME/.bash_profile
to load the config into your current shell. Verify that ANDROID_HOME
has been added to your path by running echo $PATH
.
Step 4: Creating a new application
Now all the dependencies are installed and we can create our new Application. Run this command to create a new React Native App
npx react-native init AwesomeProject
Step 5: Preparing the Android device & Running your React Native App
Open your project android folder in Android studio, Click on the AVD (Android Virtual Device) Manager from the menu list.
Select 'Create Virtual Device...' , then pick any Phone from the list and click "Next", then select the Q API Level 29 image.
Click "Next" then "Finish" to create your AVD. After this you will see the green play button next to your AVD. Click it to launch the AVD.
Now finally we are ready to run our react native app in android. Run this command in terminal
npx react-native run-android
I also wrote same blog for iOS devices. Check it here: