Getting Started

This document describes how to get started with Google VR for Android by building sample Java apps using the SDK.

We'll build one sample app in this guide:

  • Treasure Hunt, a VR app which works with any VR viewer and uses touch events to interact with the system. You need to have an Android device running KitKat or newer.

Build and Run Treasure Hunt

The following steps show how to build the Treasure Hunt app, a basic game which demonstrates the following core features of the Google VR SDK:

  • Binocular rendering: A split-screen view for each eye in VR.

  • Spatial audio: Sound seems to come from specific areas of the VR world.

  • Head movement tracking: The VR world view updates as the user moves their head.

  • Trigger input: The user can interact with the VR world by pressing a button.

In this game, you'll look around the game world to find and collect objects as quickly as possible. Note that you can run Treasure Hunt on both the Cardboard and Daydream platforms.

Prerequisites

Building the sample app requires:

  • Android Studio, 2.2.2 or higher.

  • Version 25 of the Android SDK.

  • Gradle 23.0.1 or higher. Android Studio will allow you to upgrade if your installed version is too low.

  • A physical Android device running Android 4.4 (KitKat) or higher for Cardboard apps or a Daydream Ready phone.

Download the sample code

Clone the GVR SDK from the gvr-android-sdk GitHub repository by running the following command:

git clone https://github.com/googlevr/gvr-android-sdk.git

Build the sample app

  1. Open Android Studio. On the Welcome to Android Studio screen, choose Open an existing Android Studio project, and select the directory where you cloned the repository. Android Studio will display the various gradle modules on the Project tab on the left side and the various run targets on the top toolbar.

  2. Connect your phone to your machine, select the samples-sdk-treasurehunt target and click Run to compile and run the application on your phone.

For more information about the code behind the Treasure Hunt game, see our explanation of it in the samples section.

Start your own project

Using Android Studio

After you've read up on the Google VR SDK for Android, it'll be time to create your own applications. Here's how.

  1. First, add the jcenter() to the build.gradle file at the root of your project so Gradle can find the AARs:

    allprojects {
        repositories {
            // For GVR components, the official source of the .aars is JCenter.
            jcenter()
        }
    }
    
  2. Add the appropriate dependencies to the build.gradle files in your modules. You can determine this by looking at the samples' build.gradle files to see what each one needs. For example, the SDK TreasureHunt uses:

    dependencies {
        compile 'com.google.vr:sdk-audio:1.10.0'
        compile 'com.google.vr:sdk-base:1.10.0'
    }
    

    Note that 1.10.0 is the current SDK version number and will need to be changed for future releases. This code indicates that an application similar to the Treasure Hunt sample needs the audio, base. This will also recursively fetch dependent libraries. You can see the full list of dependencies in the various POM files in the libraries directory of the SDK.

Once this is done for all of the required libraries, you will be able to reference code in the Google VR SDK in your app.

Using ProGuard with Google VR

If you are using ProGuard with your project, make sure it keeps the code used by Google VR. We do this in our code samples build.gradle file with the following:

android {
    ...
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles.add(file('../../proguard-gvr.txt'))
        }
    }
}

where proguard-gvr.txt contains the ProGuard rules you need.