Version: 2018.4
Getting started with Android development
Unity Remote

Android environment setup

To build and run for Android, you must install the Unity Android Build Support platform module. You also need to install the Android Software Development Kit (SDK) to build and run any code on your Android device. If you want to use the IL2CPP scripting backendA framework that powers scripting in Unity. Unity supports three different scripting backends depending on target platform: Mono, .NET and IL2CPP. Universal Windows Platform, however, supports only two: .NET and IL2CPP. More info
See in Glossary
, you must also install the Android Native Development Kit (NDK). By default, Unity installs a Java Development Kit based on OpenJDK.

1. Download the Android SDK

You can install the Android SDK using command line tools or through Android Studio. Android Studio provides an easy to use GUI based tool but installs additional software on your computer. Using the command line tools is a smaller download and does not install additional software, but it can be more challenging to use.

1a. Install the Android SDK using the command line tools

Install or unpack the Android SDK. After installing, open the Android SDK Manager and add at least one Android SDK Platform, the Platform Tools, the Build Tools, and the USB drivers if you’re using Windows.

To install an Android platform SDK and the associated tools:

  1. Download the Android Software command line tool.

  2. Unzip the downloaded file to a location on your hard drive.

  3. Open a command-prompt window.

  4. Navigate to the bin folder in the location where you unzipped the tools folder:

    install folder > tools > bin

  5. Use the sdkmanager command line tool to retrieve the list of packages that you can install. The installable packages include the Platform SDKs, Build Tools, Platform tools, and other tools.

    sdkmanager --list

  6. Select a version of the Platform SDK to install. Platform SDKs take the following form in the list: platforms;android-xx. The xx indicates the SDK level. The larger the number, the newer the package. Typically, you can install the latest available version. However, there might be cases where Google has released a new version of the SDK that causes errors when you build your Unity Project. In that case, you must uninstall the SDK and install an earlier version. The general format of the command for package installation is sdkmanager <package name>. You can install the corresponding Platform Tools and Build Tools at the same time.

Example: sdkmanager “platform-tools” “platforms;android–29” “build-tools;29.0.3”

Note: If Unity displays “Warning: Could not create settings” and “java.lang.IllegalArgumentException”, you must specify the –sdk_root=<path> where you extracted the downloaded SDK. For example, if the SDK manager you’re running is in the /Users/youruser/SDK/tools/bin/ directory, you must change the command above to:

sdkmanager –sdk_root=“/Users/youruser/SDK” “platform-tools” “platforms;android–29” “build-tools;29.0.3”

  1. If you are running on Windows, install the USB device drivers:

sdkmanager “extras;google;usb_driver”

1b. Install the SDK using Android Studio

Install Android studio from the Android developer portal. The Android developer portal provides detailed installation instructions.

Note: Android Studio provides some ease of use benefits, but it is not fully tested for compatibility with Unity installs. If you encounter errors, Unity recommends using the command line method.

When installing the Android platform SDK and other tools, you can typically install the latest available version. There might be cases in which Google has released a new version of the SDK that causes errors when you build your Unity Project. In that case, uninstall the SDK and install an earlier version.

Install the associated platform, build tools, and platform tools at the same time. If you are running on Windows, install the USB device drivers.

Note: When using Android Studio version 3.6 or newer, the Tools component is not installed automatically as it is considered outdated. You will have to uncheck “Hide Obsolete Packages” and then install “Android SDK Tools (Obsolete)”. Otherwise Unity will not detect the SDK.

Android SDK Tools component
Android SDK Tools component

2. Enable USB debugging on your device

To enable USB debugging, you must first enable Developer options on your device. To do this, find the build number in your device’s Settings menu. The location of the build number varies between devices; for stock Android, it’s usually in Settings > About phone > Build number. For specific information on your device and Android version, refer to your hardware manufacturer.

After you navigate to the build number using the instructions above, tap on the build number seven times. A pop-up notification saying “You are now X steps away from being a developer” appears, with “X” being a number that counts down with every additional tap. On the seventh tap, Developer options are unlocked.

Note: On Android versions prior to 4.2 (Jelly Bean), the Developer options are enabled by default.

Go to Settings > Developer options, then enable USB debugging. Android now enters debug mode when it is connected to a computer via USB.

Connect your device to your computer using a USB cable. If you are developing on a Windows computer, you might need to install the device-specific USB driver. See the manufacture website for your device for additional information.

The setup process differs for Windows and macOS and is explained in detail on the Android developer website. For more information on connecting your Android device to the SDK, refer to the Running Your App section of the Android Developer documentation.

3. Configure the Android SDK path in Unity

The first time you create a Project for Android (or if Unity later fails to locate the SDK), Unity asks you to locate the folder in which you installed the Android SDK.

If you installed the SDK using the SDK Manager, locate the SDK’s installation folder. The proper SDK location is the directory which contains the build-tools, platforms, platform-tools and tools directories.

If you installed the SDK using Android Studio, you can find the location in the Android Studio SDK Manager. To open the SDK Manager from Android Studio, go to Tools > Android > SDK Manager, or select SDK Manager in the toolbar.

To change the location of the Android SDK, in the Unity menu bar go to Unity > Preferences > External Tools.

4. Download and set up the Android NDK

If you are using the IL2CPPA Unity-developed scripting back-end which you can use as an alternative to Mono when building Projects for some platforms. More info
See in Glossary
scripting backend for Android, you need the Android Native Development Kit (NDK). It contains the toolchains (such as compiler and linker) needed to build the necessary libraries and produce the output package (APK). If you are not targeting the IL2CPP backend, you can skip this step.

Download Android NDK version r16b (64-bit) from the NDK Downloads web page. Extract the android-ndk-r16b folder to a directory on your computer and note the location.

The first time you build a Project for Android using IL2CPP, Unity asks you to locate the folder in which you installed the Android NDK. Select the root folder of your NDK installation. To change the location of the Android NDK, in the Unity Editor, navigate to the menu: Unity > Preferences to display the Unity Preferences dialog box. Here, click External Tools.

Using an alternate Java Development Kit

Unity recommends that you use the JDK installed with the Android build tools, to ensure that you receive the correct version and configuration.

If you have manually installed the JDK and do not want to duplicate the installation, you can specify the location in the Unity Preferences window. To do this, go to Preferences > External tools and enter the directory path in the JDK field:

Preferences for Android external tools
Preferences for Android external tools

Warning: The Android tools do not support JDK 9 or later; an alternate JDK must be version 8. Unity does not officially support versions of the JDK other than the one embedded in the Android Build Tools.

To change the JDK that Unity uses to build Android apps:

  1. Open the Project.

  2. Open the Preferences window:
    • In the Editor for Windows, navigate to Edit > Preferences.
    • In the Editor for the macOS, navigate to Unity > Preferences.
  3. In the left navigation column, select External Tools.

  4. Uncheck JDK Installed with Unity (recommended).

  5. In the JDK field enter the path to the JDK or use the Browse button to locate it.

Getting started with Android development
Unity Remote