# 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:

- **Daydream:** You'll need a [Daydream-ready phone](https://vr.google.com/daydream/smartphonevr/phones/)
  and a [Daydream View](https://madeby.google.com/vr/).

- **Cardboard:** You'll need an Android device running Android 4.4 'KitKat'
  (API level 19) or higher and a [Cardboard viewer](https://vr.google.com/cardboard/get-cardboard/).

Software requirements:

- [Android Studio](https://developer.android.com/studio/index.html)
  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](https://github.com/googlevr/gvr-android-sdk/releases).  

## 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**:

   <br />

   | 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](https://developers.google.com/vr/develop/android/vrview) guide. |
   | **sdk-simplevideowidget** | Widget to render a 360 degree video using `VRVideoView`. See [VR View](https://developers.google.com/vr/develop/android/vrview) guide. |
   | **sdk-video360** | Widget to render a 360 degree video. See [video360](https://developers.google.com/vr/android/samples/video360) guide. |
   | **sdk-videoplayer** | Sample activity for video playback using the Asynchronous Reprojection Video Surface API. See [Using video viewports](https://developers.google.com/vr/reference/gvr-ndk-rendering#using_video_viewports) in the Google VR NDK guide for more details. |

   <br />

## Prepare your device

- [Enable developer options](https://developer.android.com/studio/debug/dev-options.html#enable)

- [Enable USB debugging](https://developer.android.com/studio/debug/dev-options.html#debugging)

## 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. |

<br />

## 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](https://developer.android.com/studio/build/shrink-code.html)
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](https://developer.android.com/studio/build/dependencies.html)
   in the Android Studio guide.

### Configure ProGuard

If you are using [ProGuard](https://developer.android.com/studio/build/shrink-code.html) 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](https://github.com/googlevr/gvr-android-sdk/blob/master/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.

- [Google VR SDK video and panoramic image sample app walkthrough](https://developers.google.com/vr/android/samples/vrview)
- Learn about Google VR design and development principles in [Daydream elements](https://developers.google.com/vr/elements/overview).
- Learn how to [enable 6DoF tracking](https://developers.google.com/vr/develop/android/get-started) in your app.
- [Spatial audio for Android tutorial](https://developers.google.com/vr/android/spatial-audio)
- [Google VR API Reference](https://developers.google.com/vr/android/reference_overview)
- **Daydream:** Learn about implementing Daydream controller user interactions in your app:
  - Review the controller library in **gvr-android-sdk** \> **libraries** \> **sdk-controller**.
  - See also the [controller library API reference](https://developers.google.com/vr/android/reference/com/google/vr/sdk/controller/package-summary).