This document describes how to get started with Google VR for Android by building a couple sample C++ apps using the NDK.
Most NDK developers have their own preferred way of building and deploying applications. This tutorial uses Android Studio, but you should feel free to follow along in the build environment of your choice.
We'll build two sample apps in this guide:
Treasure Hunt, a Cardboard 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.
Treasure Hunt sample app
First, read about Treasure Hunt and how to build it using the SDK. The steps to build the app using the NDK are nearly the same, with the following key differences:
Download the latest version of the Android NDK.
Extract the NDK .so files by running the command
In settings.gradle, uncomment the following lines:
include ':samples:ndk-controllerpaint' include ':samples:ndk-treasurehunt'
Select samples-ndk-treasurehunt as your target.
Controller Paint sample app
This is a Daydream app that requires a Daydream-ready headset phone and a Daydream controller. If you don't have access to a Daydream controller, you can use a second phone as a controller phone by installing the Controller Emulator. You'll use the controller as a paintbrush to draw pictures on a VR canvas.
What you'll need
You should already have these if you ran the Treasure Hunt demo.
New things you'll need for this tutorial:
- A Daydream-ready phone and Daydream hardware for development.
Build the sample app
Open Android Studio. On the Welcome to Android Studio screen, choose Open an existing Android Studio project, and select the
If you haven't set up Android Studio to work with the NDK before, it will prompt you to select the Android NDK location. Click on Select NDK and either download the NDK now, or choose Select a valid NDK path to point to where you already downloaded the Android NDK.
Connect your phone to your computer using a USB cable. Select the app target and click the Run button to compile and run the application on your headset phone.
Put your phone into your Daydream viewer and try drawing things!
- To paint, click and hold the touchpad, and then move the controller in the air.
- To erase everything, tap the App button.
- To recenter the controller, press and hold the Home button for at least one second, and then release it.