How to setup a Mac OS-X development environment for React-native Android development

Published: 2016-07-22

By: MJ Rossetti

Category:
Technologies:

This document describes the process of creating a react-native android app from scratch, based on the official Getting Started Guide.

Install node and node package dependencies:

which node #> /usr/local/bin/node
brew install watchman
npm install -g react-native-cli

Download and install Android Studio.

Check JDK version:

javac -version #> javac 1.7.0_80

Initialize a new react-native app:

react-native init MyNativeApp

Try to run the app:

cd MyNativeApp && react-native run-android

To overcome the error SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.: add to ~/.bash_profile:

export ANDROID_HOME="/Users/YOUR_USERNAME/Library/Android/sdk"

Try to run the app again:

react-native run-android

To overcome the error failed to find target with hash string 'android-23' in: /Users/YOUR_USERNAME/Library/Android/sdk:

  • open Android Studio
  • navigate to Tools > Android > SDK Manager
  • then under the SDK Platforms tab, check the box for Android 6.0 (Marshmellow) - API level 23
  • then click OK to initiate a download of that version

You should see a new folder at /Users/YOUR_USERNAME/Library/Android/sdk/platforms/android-23.

Try to run the app again:

react-native run-android

To overcome the error failed to find Build Tools revision 23.0.1:

  • open Android Studio
  • navigate to Tools > Android > SDK Manager
  • then under the SDK Tools tab, check the Show Package Details box in the bottom right-hand corner
  • expand the Android SDK Build Tools line to reveal numerous versions of the build tools that can be downloaded - some say they are obsolete
  • check the box for Android SDK Build Tools 23.0.1
  • then click Apply to initiate a download of that version of the build tools

You should see a new folder at /Users/YOUR_USERNAME/Library/Android/sdk/build-tools/23.0.1.

Try to run the app again:

react-native run-android

To overcome the error Execution failed for task ':app:installDebug'... com.android.builder.testing.api.DeviceException: No connected devices!:

  • open Android Studio
  • navigate to Tools > Android > AVD Manager
  • click Create a Virtual Device
  • choose the type of device to create - Nexus 5
  • choose a release and download it - Marshmellow - 23 - x86
  • when the download finishes, select the release and click Next
  • click Finish
  • click on Duplicate from the recently-created AVD’s dropdown menu, and click Finish to copy the AVD
  • click the copied AVD’s Run/play button to launch this AVD in an emulator

… this section based on Android Studio’s instructions on how to Create and Manage Virtual Devices

Try to run the app again:

react-native run-android

SUCCESS!


Edits:

To use these tools from the command line, amend your PATH to reference their directories:

# ~/.bash_profile

#
# Android Studio
#

export ANDROID_HOME="/Users/YOUR_USERNAME/Library/Android/sdk"
export PATH=~/Library/Android/sdk/tools:$PATH # enable use of the `android` cli
export PATH=~/Library/Android/sdk/platform-tools:$PATH # enable use of the `adb` cli

replace YOUR_USERNAME with your own username

Check for connected emulators or devices:

adb devices