Skip to content

Instantly share code, notes, and snippets.

@debojyoti
Last active April 24, 2019 09:58
Show Gist options
  • Save debojyoti/52679ef57e5f8b651c44b74dcff389fc to your computer and use it in GitHub Desktop.
Save debojyoti/52679ef57e5f8b651c44b74dcff389fc to your computer and use it in GitHub Desktop.

React Native setup steps for ubuntu

Minimum Node v9.8.1 is required for setup. Go to the installation guide!

Step-1: Install react-native-cli globally

npm install -g react-native-cli

2} Install and setup jdk-8

Step-2: Install and setup jdk-8

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

Select oracle-java

sudo update-alternatives --config java

Will output:

There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
* 3            /usr/lib/jvm/java-8-oracle/jre/bin/java          1081      manual mode

And select java-8-oracle

Step-3: Download and setup Android Studio

a) Download for linux

Link: https://developer.android.com/studio/#downloads

b) Unzip it and copy to /opt/android-studio

c) Run it

cd /opt/android-studio/bin
./studio.sh

Setup accourdingly

Step-4: Update environment variables

Modify etc/environment file

Open etc/environment file and add proper jdk link

sudo nano /etc/environment 

Append Java path, Android path and gradle path in the PATH variable and add also add JAVA_HOME, ANDROID_HOME seperately

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-oracle:/opt/android/sdk/tools:/opt/android/sdk/platform-tools:/opt/android-studio/gradle/gradle-4.6/bin"
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
ANDROID_HOME="/opt/android/sdk"

Modify ~/.bashrc file

Open ~/.bashrc file and add proper jdk link

sudo nano ~/.bashrc 

And the following line at the end

export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export ANDROID_HOME=/opt/android/sdk

Execute both of them

source /etc/environment 
source ~/.bashrc

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

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 9 (Pie) entry, then make sure the following items are checked:

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.

Step-5: Install Watchman

git clone https://github.com/facebook/watchman.git
cd watchman
git checkout v4.9.0  # the latest stable release
sudo apt-get install libtool m4 automake pkg-config
./autogen.sh
./configure
sudo apt-get install python-dev python3-dev
make
sudo make install

Step-6: Create a new project

react-native init AwesomeProject

Step-7: Run the project in your android device

First connect your device via usb and make sure developers tool and usb debugging is enabled.
After connecting the device, it may ask to allow usb debugging, accept it.
Then run the command inside the root directory of the project.

react-native run-android

Step-8: View logs in terminal

react-native log-android
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment