Overview
React Native is a mobile development javascript framework that was created by Facebook used to create cross-platform native apps. Unlike other frameworks like Ionic, when you build a react native app, you aren’t building a hybrid app, you’re actually building a native app as you would with Java or Swift. The other added benefit is that one codebase is reused for both Android and iOS platforms so this can reap huge benefits from a business standpoint. React Native Apps are written in javascript and the UI is built using the react javascript library.
This article will walk you through how to set up React Native on Linux and create a React Native project. (Android Guide)
What you’ll need
For Android testing
- A working Java Installation
- Android Sdk
- Android Debug Bridge(adb)
Requirement
- NodeJS and NPM
Installing requirements
Java and Android SDK
We’ll install Java and the Java Runtime Environment, then we’ll install Oracle Java 8 as it is a requirement of gradle when running the react native app.
- JDK and JRE
sudo apt install default-jdk default-jre
- Oracle JDK
sudo add-apt-repository ppa:webupd8team/java
sudo apt update
sudo apt install oracle-java8-installer
- Android SDK and ADB
To download the SDK, I recommend downloading the Android Studio IDE which will download the SDK automatically and store it in your /home directory. You can also download the command line tools and use the included sdkmanager
to achieve the same results. In any case you’ll have to visit: the Android Studio download page and choose the desired option.
Next, download ADB because you’ll need it when debugging on a connected device.
sudo apt install adb
NodeJS and NPM
sudo apt-get install -y build-essential
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
#the source above can change depending on the version of node that's currently supported
sudo apt install -y nodejs
sudo apt install npm
To verify that node is installed correctly:
node -v
# Your output should be the version of node installed on your system
Install React Native
Similar to react, it’s possible to install React Native using the Create React Native App
npm package but we won’t be doing that because it requires Expo which in turn requires an active internet connection during development. Instead, we’ll be installing the React Native CLI which is more flexible in my opinion.
sudo npm i -g react-native-cli
Next, let us create our first project.
react-native init OurFirstProject
The initial set up will take a while so you’ll need to exercise some patience. When the set up is complete, plugin your android device and make sure you’ve enable USB Debugging on it. To make sure your device is properly connected:
adb devices
# Your output should display your device ID and make
If everything looks good, change into your project directory and run the following command.
cd OurFirstProject
react-native run-android
There are a few things that might go wrong. You might get an error prompting you to point to your android sdk path. In that case:
While still in your root project directory.
cd android
touch local.properdies
# then edit this file to point to your android sdk path
nano local.properties
sdk.dir = [path to sdk]
Then try running the app again. Another issue you might face is a connectivity issue to your device. In that case, try running:
adb reverse tcp:8081 tcp:8081
Try running your app again. If it succeeds, then you can begin editing your app. If it fails, read the console error and try to find possible solutions online.
Cheers!