react-native/docs/GettingStartedOnLinux.md

4.4 KiB

id title layout category permalink next
getting-started-linux Getting Started on Linux docs Quick Start docs/getting-started-on-linux.html android-setup

This guide is essentially a beginner-friendly version of the Getting Started page for React Native on Linux.

Prerequisites

For the purposes of this guide, we assume that you're working on Ubuntu Linux 14.04 LTS.

Before following this guide, you should have installed the Android SDK and run a successful Java-based "Hello World" app for Android.

See Android Setup for details.

Installing NodeJS

The first thing you need to do is to install NodeJS, a popular Javascript implementation.

Fire up the Terminal and paste the following commands to install NodeJS from the NodeSource repository:

sudo apt-get install -y build-essential
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo ln -s /usr/bin/nodejs /usr/bin/node

NOTE: The above instructions are for Ubuntu. If you're on a different distro, please follow the instructions on the NodeJS website.

Installing Watchman

watchman is a tool by Facebook for watching changes in the filesystem. You need to install it for better performance and avoid a node file-watching bug.

Paste the following into your terminal to compile watchman from source and install it:

git clone https://github.com/facebook/watchman.git
cd watchman
git checkout v4.1.0  # the latest stable release
./autogen.sh
./configure
make
sudo make install

Installing Flow

Flow is a static type checker for JavaScript. To install it, paste the following in the terminal:

sudo npm install -g flow-bin

Setting up an Android Device

Let's set up an Android device to run our starter project.

First thing is to plug in your device and check the manufacturer code by using lsusb, which should output something like this:

$ lsusb
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 22b8:2e76 Motorola PCS 
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

These lines represent the USB devices currently connected to your machine.

You want the line that represents your phone. If you're in doubt, try unplugging your phone and running the command again:

$ lsusb
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

You'll see that after removing the phone, the line which has the phone model ("Motorola PCS" in this case) disappeared from the list. This is the line that we care about.

Bus 001 Device 003: ID 22b8:2e76 Motorola PCS

From the above line, you want to grab the first four digits from the device ID:

22b8:2e76

In this case, it's 22b8. That's the identifier for Motorola.

You'll need to input this into your udev rules in order to get up and running:

echo SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", MODE="0666", GROUP="plugdev" | sudo tee /etc/udev/rules.d/51-android-usb.rules

Make sure that you replace 22b8 with the identifier you get in the above command.

Now check that your device is properly connecting to ADB, the Android Debug Bridge, by using adb devices.

List of devices attached
TA9300GLMK	device

For more information, please see the docs for running an Android app on your device.

Next Steps

Your Android device and your tools are all ready to go. You can now follow the instructions in the Quick Start guide to install React Native and start your first project.