Setting up React Native development environment on Linux Ubuntu 20.04

Checklist

  • Install Node
  • Install JDK
  • Install Watchman (optional)
  • Install Android Studio
  • Install Android SDK
  • Configure Android environment variables
  • Setup physical Android device

The entire process above gets fairly simple once you have done it at least twice.. Most of it can be done via the Terminal and can be scripted. Installing the SDK is the one step that you have got to do from inside Android Studio..

Node

# install nvm (Node Version Manager)
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

restart the Terminal now so that the nvm command is available

# install latest Node LTS with nvm
nvm install --lts

Java Development Kit (JDK)

# install JDK version 8
sudo apt install -y openjdk-8-jdk-headless openjdk-8-jre

Watchman

Homebrew now works on Linux!

# install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

will take some time installing core taps, around ~322mb in downloads..

Now, install Watchman with Homebrew

# install latest build from Github
brew install --HEAD watchman

Setup physical android device

If your phone is not being detected, try using a different USB cable. Some cables only support charging and not data transfer

# lsusb
Bus 002 Device 004: ID 0e8d:201d MediaTek Inc. Infinix HOT 9
0e8d:201d
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="0e8d", MODE="0666", GROUP="plugdev"' | sudo tee /etc/udev/rules.d/51-android-usb.rules

At this point, if you run adb devices, you'll get

List of devices attached
054783604A010925    unauthorized

To fix that unauthorized, disconnect and reconnect your phone at this point. The next time you connect, it'll show you a Allow USB debugging popup. Tap ALLOW. Also check that box that says Always allow from this computer if you don't wanna do this every time..

Now if you run adb devices, you should see device instead of unauthorized

List of devices attached
054783604A010925    device

We're set at this point

Setup physical device for live reloads

USB:

adb -s 054783604A010925 reverse tcp:8081 tcp:8081

Android Studio

sudo snap install android-studio --classic

Update paths. The default install location for Android when installed using snap is ?. I installed it in a custom location, so i provided that. Update this location.

You can find out the SDK location from Android Studio > Tools > SDK Manager > Android SDK Location

echo "

# Android PATHs
export ANDROID_HOME="/media/aamnah/Files/Dev/Android"
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
" >> ${HOME}/.bashrc

You can now confirm this with which android

Links

Please note that this site and the posts on it are, and will always be, a work in progress. If i waited for perfection, i’d never get anything done.