Getting Started with React Native on Mac
2 min readMar 18, 2018
Prerequisite:
- We should install java8 on mac beforehand: https://medium.com/@at_ishikawa/install-java-by-homebrew-on-mac-d99aff457c1f
- Install Android Studio:
https://developer.android.com/studio/index.html
Install React Native
Follow instructions on tutorial here
brew install node
brew install watchman
npm install -g react-native-cli
Create a project
react-native init react_native_sample
cd react_native_sample
Run a react native on android
First, install android studio and run an emulator, as the tutorial describes.
Then, run a following command inside a react native project.
react-native run-android
And if an emulator screen is like the below, running react native is succeeded.
Troubleshootings
- Errors for java9, instead of java8, when running
react-native run-android
$ react-native run-android
Scanning folders for symlinks in /path/to/react-native/node_modules (27ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...FAILURE: Build failed with an exception.* What went wrong:
Could not determine java version from '9.0.4'.* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
2. Cause (the emulator of API version is too new). If the version of the API of an emulator is 23, it can be solved
:app:installDebug04:54:24 E/ddms: ADB rejected shell command (getprop): closedSkipping device 'Pixel_2_XL_API_27(AVD)' for 'app:debug': Unknown API Level:app:installDebug FAILEDFAILURE: Build failed with an exception.* What went wrong:Execution failed for task ':app:installDebug'.> Failed to install on any devices.