<- all posts

An updated guide to installing React Native without Android Studio

Rodrigo Klosowski
Published by Rodrigo KlosowskiSeptember 11, 2020 Ā· 2 min read

Certainly, before setting up a React Native development environment you follow theĀ official facebook’s getting started guide, which requires the Android Studio setup, but if you are not an Android native developer, you might want to skip its heavy installation, save some disk space, time and hack things around. šŸ’»šŸ¤“


tldr;

How to install React Native without Android Studio:

1. Install JDK8

brew cask install adoptopenjdk/openjdk/adoptopenjdk8

2. Install node and watchman

brew install nodebrew install watchman

3. Download Android SDK

Now instead of installing the whole Android Studio package, we will only use the Android SDK. Start by openingĀ this android developer link, scroll to theĀ ā€œCommand line tools onlyā€Ā section, and download the zip file.

After downloading it, extract the zip file to the following path:

/opt/android/cmdline-tools/

4. Export the ANDROID_HOME environment variable

The React Native tools require some environment variables to be set up to build apps with native code.

Instead of only exporting the ANDROID_HOME to the current session of the terminal, we make sure that it’s permanently added to the terminal by adding the following lines to yourĀ $HOME/.bash_profileĀ orĀ $HOME/.bashrcĀ (if you are usingĀ zshĀ thenĀ ~/.zprofileĀ orĀ ~/.zshrc) config file:

export ANDROID_HOME=/opt/android

Make sure you restart the bash to apply the changes.

Also, make sure you have writing permissions to the android home folder:

sudo chown -R $(whoami) $ANDROID_HOME

5. Install the required SDK packages

The official React Native environment setup recommends installing the following SDK packages:

  • Android SDK Platform 29
  • Intel x86 Atom_64 System ImageĀ orĀ Google APIs Intel x86 Atom System Image
  • Android SDK Build-Tools 29.0.2

So, instead of selecting these packages from the Android Studio SDK Manager, we will install it using the command line with the following command:

$ANDROID_HOME/cmdline-tools/tools/bin/sdkmanager "platform-tools" "platforms;android-29" "build-tools;29.0.2" "add-ons;addon-google_apis-google-24"

A very useful link isĀ this gist, which keeps track of all the available packages, its description, and its versions.

6.Ā Install platform tools to the path

In a later development, having the command line tools available will make everything easier, so similar to what we did to the ANDROID_HOME environment variable, we add the following lines to theĀ $HOME/.bash_profileĀ orĀ $HOME/.bashrcĀ (if you are usingĀ zshĀ thenĀ ~/.zprofileĀ orĀ ~/.zshrc) config file:

export PATH="${ANDROID_HOME}/platform-tools:${PATH}"

Again, make sure to restart the bash.

7. Test the installation

That’s all! šŸ˜Ž

To test if your development environment works, run:

npx react-native init AwesomeProjectcd AwesomeProjectnpx react-native run-android

And it should work fine. Thanks for reading!