Quickstart for Google VR SDK for Android

Use the Google VR SDK to build apps for Daydream and Cardboard. This guide shows you how to set up Android Studio for Google VR development and try out a sample app.

Set up your development environment

Hardware requirements:

Software requirements:

  • Android Studio version 2.3.3 or higher.

  • Android SDK 7.1.1 'Nougat' (API level 25) or higher.
    In Android Studio, go to Preferences > Appearance and Behavior > System Settings > Android SDK (includes samples) to review or update installed SDKs.

  • The latest Google VR SDK for Android.

Open the Google VR SDK project in Android Studio

  1. Extract the downloaded Google VR SDK into a convenient location.

  2. Open Android Studio and select Open an existing Android Studio project.
    Select the directory where you extracted the Google VR SDK.

  3. In the Project window, review the sample gradle modules in gvr-android-sdk > samples:

    Sample Description
    sdk-hellovr VR sample app in which you look for and collect objects.
    sdk-controllerclient Sample showing how to receive and handle Daydream controller input.
    sdk-simplepanowidget Widget to load a panoramic image from disk. See VR View guide.
    sdk-simplevideowidget Widget to render a 360 degree video using VRVideoView. See VR View guide.
    sdk-video360 Widget to render a 360 degree video. See video360 guide.
    sdk-videoplayer Sample activity for video playback using the Asynchronous Reprojection Video Surface API.
    See Using video viewports in the Google VR NDK guide for more details.

Prepare your device

Build and run the sample app

  1. Connect your phone to your machine using a USB cable.

  2. In Android Studio, select Run > Run... and select the samples-sdk-hellovr target.
    Android Studio compiles and runs the application on your phone.

  3. Put your phone into your viewer and use the app.

    • Look around for the large cube.
    • Daydream: Point the controller at the cube and press the touchpad button to collect it.
      Cardboard: Look at the cube and press the Cardboard button to collect it.
    • The cube moves to a new location after a button press.

The sample app shows the following core features of the Google VR SDK:

Feature Description
Stereo rendering App views are rendered in stereo to create a 3D effect.
Spatial audio Sounds come from different areas of the VR world, increasing its realism.
Head movement tracking Users can move their heads to look around a VR world. Views update in response to head movement.
User input Users can interact with the app using a Daydream controller or Cardboard button.

Using Google VR in your own projects

To use the Google VR SDK or NDK in your own projects, set up Google VR dependencies. If you are using ProGuard in your app, add rules to ensure that it does not obfuscate any SDK or NDK code.

Setting up Google VR dependencies

  1. Configure your project level build.gradle file:

    • Make sure that the default jcenter() repository location is declared.
    • Declare an Android Gradle plugin dependency:
      Google VR SDK projects: Use gradle:2.3.3 or higher.
      Google VR NDK projects: Use gradle-experimental:0.9.3 or higher.

        allprojects {
          repositories {
              jcenter()
          }
        }
      
        dependencies {
          // The Google VR SDK requires version 2.3.3 or higher.
          classpath 'com.android.tools.build:gradle:2.3.3'
      
          // The Google VR NDK requires experimental version 0.9.3 or higher.
          // classpath 'com.android.tools.build:gradle-experimental:0.9.3'
        }
      
  2. Add Google VR SDK library dependencies in your module level build.gradle files. You can see available libraries and their versions in gvr-android-sdk > libraries.

    As an example, review the dependencies declared for the sample app in gvr-android-sdk > samples > sdk-hellovr > build.gradle.

      dependencies {
         // Adds Google VR spatial audio support
         compile 'com.google.vr:sdk-audio:1.160.0'
    
         // Required for all Google VR apps
         compile 'com.google.vr:sdk-base:1.160.0'
      }
    

    For more information, see Add Build Dependencies in the Android Studio guide.

Configure ProGuard

If you are using ProGuard to minimize your app's APK file, make sure that ProGuard does not obfuscate any Google VR SDK or NDK code. This makes it easier to debug stack traces in release builds.

Add the Google VR ProGuard proguard-gvr.txt rules to your module level build.gradle file:

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

Next steps

To learn more about the Google VR SDK, see the following resources.