|
| 1 | +## Installing dependencies |
| 2 | + |
| 3 | +You will need Node, Watchman, the React Native command line interface, a JDK, and Android Studio. |
| 4 | + |
| 5 | +While you can use any editor of your choice to develop your app, you will need to install Android Studio in order to set up the necessary tooling to build your React Native app for Android. |
| 6 | + |
| 7 | +<h3>Node & Watchman</h3> |
| 8 | + |
| 9 | +We recommend installing Node and Watchman using [Homebrew](https://brew.sh/). Run the following commands in a Terminal after installing Homebrew: |
| 10 | + |
| 11 | +```shell |
| 12 | +brew install node |
| 13 | +brew install watchman |
| 14 | +``` |
| 15 | + |
| 16 | +If you have already installed Node on your system, make sure it is Node 18.18 or newer. |
| 17 | + |
| 18 | +[Watchman](https://facebook.github.io/watchman) is a tool by Facebook for watching changes in the filesystem. It is highly recommended you install it for better performance. |
| 19 | + |
| 20 | +<h3>Java Development Kit</h3> |
| 21 | + |
| 22 | +We recommend installing the OpenJDK distribution called Azul **Zulu** using [Homebrew](https://brew.sh/). Run the following commands in a Terminal after installing Homebrew: |
| 23 | + |
| 24 | +```shell |
| 25 | +brew install --cask zulu@17 |
| 26 | + |
| 27 | +# Get path to where cask was installed to find the JDK installer |
| 28 | +brew info --cask zulu@17 |
| 29 | + |
| 30 | +# ==> zulu@17: <version number> |
| 31 | +# https://www.azul.com/downloads/ |
| 32 | +# Installed |
| 33 | +# /opt/homebrew/Caskroom/zulu@17/<version number> (185.8MB) (note that the path is /usr/local/Caskroom on non-Apple Silicon Macs) |
| 34 | +# Installed using the formulae.brew.sh API on 2024-06-06 at 10:00:00 |
| 35 | + |
| 36 | +# Navigate to the folder |
| 37 | +open /opt/homebrew/Caskroom/zulu@17/<version number> # or /usr/local/Caskroom/zulu@17/<version number> |
| 38 | +``` |
| 39 | + |
| 40 | +After opening Finder, double click the `Double-Click to Install Azul Zulu JDK 17.pkg` package to install the JDK. |
| 41 | + |
| 42 | +After the JDK installation, add or update your `JAVA_HOME` environment variable in `~/.zshrc` (or in `~/.bash_profile`). |
| 43 | + |
| 44 | +If you used above steps, JDK will likely be located at `/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home`: |
| 45 | + |
| 46 | +```shell |
| 47 | +export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home |
| 48 | +``` |
| 49 | + |
| 50 | +The Zulu OpenJDK distribution offers JDKs for **both Intel and M1 Macs**. This will make sure your builds are faster on M1 Macs compared to using an Intel-based JDK. |
| 51 | + |
| 52 | +If you have already installed JDK on your system, we recommend JDK 17. You may encounter problems using higher JDK versions. |
| 53 | + |
| 54 | +<h3>Android development environment</h3> |
| 55 | + |
| 56 | +Setting up your development environment can be somewhat tedious if you're new to Android development. If you're already familiar with Android development, there are a few things you may need to configure. In either case, please make sure to carefully follow the next few steps. |
| 57 | + |
| 58 | +<h4 id="android-studio">1. Install Android Studio</h4> |
| 59 | + |
| 60 | +[Download and install Android Studio](https://developer.android.com/studio/index.html). While on Android Studio installation wizard, make sure the boxes next to all of the following items are checked: |
| 61 | + |
| 62 | +- `Android SDK` |
| 63 | +- `Android SDK Platform` |
| 64 | +- `Android Virtual Device` |
| 65 | + |
| 66 | +Then, click "Next" to install all of these components. |
| 67 | + |
| 68 | +> If the checkboxes are grayed out, you will have a chance to install these components later on. |
| 69 | +
|
| 70 | +Once setup has finalized and you're presented with the Welcome screen, proceed to the next step. |
| 71 | + |
| 72 | +<h4 id="android-sdk">2. Install the Android SDK</h4> |
| 73 | + |
| 74 | +Android Studio installs the latest Android SDK by default. Building a React Native app with native code, however, requires the `Android 15 (VanillaIceCream)` SDK in particular. Additional Android SDKs can be installed through the SDK Manager in Android Studio. |
| 75 | + |
| 76 | +To do that, open Android Studio, click on "More Actions" button and select "SDK Manager". |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +> The SDK Manager can also be found within the Android Studio "Settings" dialog, under **Languages & Frameworks** → **Android SDK**. |
| 81 | +
|
| 82 | +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 15 (VanillaIceCream)` entry, then make sure the following items are checked: |
| 83 | + |
| 84 | +- `Android SDK Platform 35` |
| 85 | +- `Intel x86 Atom_64 System Image` or `Google APIs Intel x86 Atom System Image` or (for Apple M1 Silicon) `Google APIs ARM 64 v8a System Image` |
| 86 | + |
| 87 | +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 `35.0.0` is selected. |
| 88 | + |
| 89 | +Finally, click "Apply" to download and install the Android SDK and related build tools. |
| 90 | + |
| 91 | +<h4>3. Configure the ANDROID_HOME environment variable</h4> |
| 92 | + |
| 93 | +The React Native tools require some environment variables to be set up in order to build apps with native code. |
| 94 | + |
| 95 | +Add the following lines to your `~/.zprofile` or `~/.zshrc` (if you are using `bash`, then `~/.bash_profile` or `~/.bashrc`) config file: |
| 96 | + |
| 97 | +```shell |
| 98 | +export ANDROID_HOME=$HOME/Library/Android/sdk |
| 99 | +export PATH=$PATH:$ANDROID_HOME/emulator |
| 100 | +export PATH=$PATH:$ANDROID_HOME/platform-tools |
| 101 | +``` |
| 102 | + |
| 103 | +Run `source ~/.zprofile` (or `source ~/.bash_profile` for `bash`) to load the config into your current shell. Verify that ANDROID_HOME has been set by running `echo $ANDROID_HOME` and the appropriate directories have been added to your path by running `echo $PATH`. |
| 104 | + |
| 105 | +> Please make sure you use the correct Android SDK path. You can find the actual location of the SDK in the Android Studio "Settings" dialog, under **Languages & Frameworks** → **Android SDK**. |
| 106 | +
|
| 107 | +<h2>Preparing the Android device</h2> |
| 108 | + |
| 109 | +You will need an Android device to run your React Native Android app. This can be either a physical Android device, or more commonly, you can use an Android Virtual Device which allows you to emulate an Android device on your computer. |
| 110 | + |
| 111 | +Either way, you will need to prepare the device to run Android apps for development. |
| 112 | + |
| 113 | +<h3>Using a physical device</h3> |
| 114 | + |
| 115 | +If you have a physical Android device, you can use it for development in place of an AVD by plugging it in to your computer using a USB cable and following the instructions [here](running-on-device.md). |
| 116 | + |
| 117 | +<h3>Using a virtual device</h3> |
| 118 | + |
| 119 | +If you use Android Studio to open `./AwesomeProject/android`, you can see the list of available Android Virtual Devices (AVDs) by opening the "AVD Manager" from within Android Studio. Look for an icon that looks like this: |
| 120 | + |
| 121 | +<img src="/docs/assets/GettingStartedAndroidStudioAVD.svg" alt="Android Studio AVD Manager" width="100"/> |
| 122 | + |
| 123 | +If you have recently installed Android Studio, you will likely need to [create a new AVD](https://developer.android.com/studio/run/managing-avds.html). Select "Create Virtual Device...", then pick any Phone from the list and click "Next", then select the **VanillaIceCream** API Level 35 image. |
| 124 | + |
| 125 | +Click "Next" then "Finish" to create your AVD. At this point you should be able to click on the green triangle button next to your AVD to launch it. |
| 126 | + |
| 127 | +<h3>That's it!</h3> |
| 128 | + |
| 129 | +Congratulations! You successfully set up your development environment. |
| 130 | + |
| 131 | +<center><img src="/docs/assets/GettingStartedCongratulations.png" width="150"></img></center> |
| 132 | + |
| 133 | +<h2>Now what?</h2> |
| 134 | + |
| 135 | +- If you want to add this new React Native code to an existing application, check out the [Integration guide](integration-with-existing-apps.md). |
| 136 | +- If you're curious to learn more about React Native, check out the [Introduction to React Native](getting-started). |
0 commit comments