Android Studio Basics

This guide introduces the Android Studio IDE and reviews some basic features, including how to build and run sample projects.

Before using this guide, follow all of the instructions in Device Setup and Android Development Software Setup. The native samples referenced in this topic can be found at \ovr_sdk_mobile\VrSamples in the Mobile SDK.

Getting Started with Oculus Native Samples: Import Gradle Project

  1. If this is the first time you are launching Android Studio, select Open an existing Android Studio project. If you have launched Android Studio before, click File > Open instead.
  2. Open any build.gradle project file from the Mobile SDK VrSamples folders. For example, VrSamples/VrCubeworld_Framework/Projects/Android/build.gradle.
  3. When asked if you would like the project to use the Gradle wrapper, click OK.

Troubleshooting Gradle Sync Errors

Here are some possible solutions if Android Studio reports a Gradle sync or configuration error:

  • The most common cause of such an error is that the Android SDK or NDK locations are wrong. Verify that the SDK and NDK locations are specified correctly in File > Project Structure. If either are wrong or missing, you cannot continue until you fill in the correct path.
  • On macOS, sometimes Android Studio reports a missing SDK location error even when the correct paths are listed in the Project Structure dialog box. To correct this problem, copy the file from your project folder up to the root of your Oculus Mobile SDK folder.

Project Overview

Android Studio displays project files in the Android view by default. We recommend changing it to the Project view, which provides a good overview of the entire directory structure and highlights imported project directories in bold.

Select Target Configuration, Build, and Run

Make sure you have followed the configuration steps in Device Setup - Oculus Android and Android Development Software Setup to ensure your device and development environment are configured appropriately.

Before building, select the target configuration you wish to build by selecting Edit Configurations in the project menu in the Android Studio toolbar.

To build and run your app:

  1. Click Run in the toolbar.

  2. The Select Deployment Target dialog box appears. This is sometimes set to an emulator by default.
  3. Select a device listed under Connected Device instead.

  4. If your device asks you to Allow USB debugging, click OK.

Troubleshooting: If USB debugging does not seem to be working:

  1. Go to Developer Options on your phone.
  2. Toggle USB Debugging off and then back on.

Troubleshooting: If stepping into certain functions results in an illegal instruction exception (SIGILL)/crash while debugging:

  1. In Android Studio, go to Run > Debug > Edit Configurations.
  2. Select the Debugger pane.
  3. Select the LLDB Post Attach Commands pane.
  4. Click + to add a new command.
  5. Add the following command: process handle --pass true --stop false --notify true SIGILL

Syncing Projects

If you edit a *.gradle file or install an update to the Oculus Mobile SDK which includes updated Gradle projects, click Sync Project with Gradle Files to update your Android Studio project files.