Quickly Building a React Native App

Haseeb Chaudhary
6 min readJun 28, 2021

Setting up your first app doesn’t need to be too daunting. A step by step guide.

Photo by Christina @ wocintechchat.com on Unsplash

This article will show you how to get your first app up and running super quick. For this I’m assuming your development environment is macOS and your target iOS is

Approach Taken

A purist method is adopted where we build the native app as would clasically be used to deploy in Google Play or Apple Store. There are alternative methods which use Expo. The relative differences shown below:

Here we use React Native approach not Expo.

If you use the Expo approach the you need to run an Expo server locally and install a Expo client on your mobile (or run a mobile simulator). All changes can be done on the Expo server and the App is updated in seconds. Over the air (OTA).

If we use the React Native approach we run everything in the mobile device (or simulator). Push the code to Google Play and Apple Store as per usual. the updates take much longer to be applied as the who app needs to be redeployed. However, it’s a more of a purist approach.

Setup

Here we’re going to use React Native CLI, this is the process to follow when you want the freedom to be able to integrate into other parts of the application.

Dependencies

You will need Node, Watchman, the React Native command line interface, a JDK, and Android Studio.

Node & Watchman

brew install node
brew install watchman

If you have already installed Node on your system, make sure it is Node 12 or newer.

Watchman is a tool by Facebook for watching changes in the filesystem. It is highly recommended you install it for better performance.

Java Development Kit

Install a version of java.

brew install --cask adoptopenjdk/openjdk/adoptopenjdk8

If you have already installed JDK on your system, make sure it is JDK 8 or newer.

Photo by Austin Distel on Unsplash

Android Studio

Ensure you install Android Studio with these components.

  • Android SDK
  • Android SDK Platform
  • Android Virtual Device

Android Studio installs the latest Android SDK by default. Building a React Native app with native code, however, requires the Android 10 (Q) SDK in particular. Additional Android SDKs can be installed through the SDK Manager in Android Studio.

To do that, open Android Studio, click on “Configure” button and select “SDK Manager”.

Select the “SDK Platforms” tab from within the SDK Manager, then check the box next to “Show Package Details” in the bottom right corner. Look for and expand the Android 10 (Q) entry, then make sure the following items are checked:

  • Android SDK Platform 29
  • 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 29.0.2 is selected and check the "Android SDK Command-line Tools (latest)".

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.

Add 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=$HOME/Library/Android/sdkexport PATH=$PATH:$ANDROID_HOME/emulatorexport PATH=$PATH:$ANDROID_HOME/toolsexport PATH=$PATH:$ANDROID_HOME/tools/binexport PATH=$PATH:$ANDROID_HOME/platform-tools

.bash_profile is specific to bash. If you're using another shell, you will need to edit the appropriate shell-specific config file.

Type source $HOME/.bash_profile for bash or source $HOME/.zprofile to load the config into your current shell. Verify that ANDROID_HOME has been set by running echo $ANDROID_HOME and the appropriate directories have been added to your path by running echo $PATH.

Please make sure you use the correct Android SDK path. You can find the actual location of the SDK in the Android Studio “Preferences” dialog, under Appearance & Behavior → System Settings → Android SDK.

It’s really important too get your JAVA HOME path correct. Begin by first checking what you have setup:

echo $JAVA_HOME#if JAVA HOME is empty and does not have a line like the following corresponding to your installed version then you need to set this
/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home
#to check JAVA installed
java -version
#check your shell running
echo $SHELL
#If you get this /bin/zsh then you're running zsh shell
vi ~/.zshrc
# add the following anywhere
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home

React CLI

With npx react-native <command>, the current stable version of the CLI will be downloaded and executed at the time the command is run.

Photo by UX Indonesia on Unsplash

Launch a New Mobile App

React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using npx, which ships with Node.js. Let's create a new React Native project called "BadAssProject":

npx react-native init BadAssProject

Get a Virtual Device Ready

If you use Android Studio to open ./BadAssProject/android, you can see the list of available Android Virtual Devices (AVDs) by opening the "AVD Manager" from within Android Studio. Look for an icon that looks like this:

If you have recently installed Android Studio, you will likely need to create a new AVD. 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. At this point you should be able to click on the green triangle button next to your AVD to launch it, then proceed to the next step.

Start the App

Let Metro Bundler run in its own terminal. Open a new terminal inside your React Native project folder. Run the following:

npx react-native run-android

npx react-native run-android is one way to run your app - you can also run it directly from within Android Studio.

Making Changes

The BadAss project can be modified bu just editing App.js in the project folder.

You can now think about how to integrate your app so its updated from an API and adding more features.

Why Build an App?

If this is your first App and you want to go further down a startup route then have a think about what is the problem or pain point you want to fix? What value does your App provide? And then and only then think about your App and the solution you will build. When you do build the solution get the user stories correct, then wireframe and then code. I hope to write a further post soon detailing how to setup a simple API to provide content to the App. If you have questions please feel free to reach out. I build stuff at elbornlab.com.

--

--