The development target OS is macOS, and both of Android and iOS will instruct below.
Node, Watchman, the React Native CLI, and Xcode are required.
Node, Watchman
- NodeJS: version 8.11.1(LTS) is available now
- Watchman: is a tool by Facebook for watching changes in the filesystem. It is highly recommended you install it for better performance.
Both of then, you can install by Homebrew
brew install node
brew install watchman
The React Native CLI
Install React Native command line interface via npm
npm install -g react-native-cli
:::warning If you get an error like Cannot find module 'npmlog', try installing npm directly: curl -0 -L https://npmjs.org/install.sh | sudo sh. :::
Xcode
The easist way to install Xcode is via the Mac App Store. Installing Xcode will also install the iOS Simulator and all the necessary tools to build your iOS app. Make sure it is version 8 or higher.
Command Line Tools
- Open Xcode.
- Choose "Preferences..." from the Xcode menu.
- Switch to "Location" tab.
- Install the most recent version Command Line Tools.
Use React Native command line to create a new app call "AwesomeProject"
react-native init AwesomeProject
cd AwesomeProject
react-native run-ios
You should see your new app running in the iOS Simulator shortly.
You can also run it directly from within Xcode.
Modifying app
- Entry point is "App.js".
- Hit ⌘R in your iOS Simulator to reload the app.
Node, Watchman, the React Native CLI, JDK, and Android Studio are required.
Node, Watchman
As iOS, Node and Watchman are installed as below:
brew install node
brew install watchman
The React Native CLI
Install React Native command line interface via npm
npm install -g react-native-cli
Java Development Kit
Java SE Development Kit (JDK) is required. Download and install JDK 8 or newer.
Android development environment
- Install Android Studio
- Choose Custom install step, make sure options as below are checked.
- Android SDK
- Android SDK Platform
- Performance (Intel ® HAXM)
- Android Virtual Device
Install Android SDK
React Native require Android 6.0 (Marshmallow) or higher.
SDK manager can be accessed from the "Welcom Android Studio" screen.
- Click "Configure"
- Select "SDK Manager"
- Select "SDK Platforms"
- Click "Show Package Details"
- Look for "Android 6.0 (Marshmallow)", make sure options as below are checked.
- Google APIs
- Android SDK Platform 23
- Intel x86 Atom_64 System Image
- Google APIs Intel x86 Atom_64 System Image
- Select "SDK Tools" and check "Show Package Detail" as well
- Look for "Android SDK Build-Tools" and make sure 23.0.1 is selected.
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:
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
:::warning You use instructions as below to edit enviroment variables: touch ~/.bash_profile; open ~/.bash_profile :::
-
Type source $HOME/.bash_profile to load the config into your current shell.
-
Verify that ANDROID_HOME has been added to your path by running echo $PATH.
You will see enviroment path as below:
Use React Native command line to create a new app call "AwesomeProject"
react-native init AwesomeProject
All avaliable devices are listed in Android Virtual Devices (AVDs) by opening the "AVD Manager" from within Android Studio.
- Select "Phone" category, exist phone image (maybe is Nexus 5X API 27 x86) and click next.
- Select to "x86 images" tab
- Looking for Marshmallow API Level 23, x86_64 ABI image with a Android 6.0 (Google APIs) target.
- Click "Next" and "Finish" to create image
- You can run the device by pressing "Start" button
cd AwesomeProject
react-native run-android
You should see your new app running in the Android Simulator shortly.
You can also run it directly from within Android Studio.
Modifying app
- Entry point is "App.js".
- Press the R key twice or select Reload from the Developer Menu (⌘M) to see changes.
Reference
- https://facebook.github.io/react-native/docs/getting-started.html
- https://facebook.github.io/react-native/docs/running-on-device.html
- http://blog.ctrlxctrlv.net/mac-environment-path/
- https://stackoverflow.com/questions/30461201/how-do-i-edit-path-bash-profile-on-osx
- https://developer.android.com/studio/run/managing-avds.html