How to run hello_xr on Oculus Quest
This post describes how to get the OpenXR native sample application known as hello_xr running on Oculus Quest and Quest 2 hardware.
As of writing there does not appear to be a comprehensive step-by-step guide on how to build hello_xr for Android and get it running on Oculus Quest hardware. There are a few dot points on the Oculus Mobile developer site, but it took me some time to get things working. Hopefully this saves the next person that time.
Note that these instructions could well become obsolete as parts of this process change. Also note that these instructions are written for use on Windows but I don’t imagine it will be too difficult to adapt this guide for other platforms.
Prerequisite Steps
There are a few things we need to do before we begin in order to get the Oculus Quest hardware and Android Studio set up correctly
- Follow the steps in Oculus Mobile Device Setup and enable developer mode on your device
- Follow the steps in Android Studio Setup for Oculus Mobile Development to install Android Studio and set it up to build Oculus mobile applications
Download the Oculus OpenXR Mobile SDK
As of writing, the standard OpenXR Android loader does not appear to work for Oculus Quest, so we have to link against the custom OpenXR loader library provided by Oculus. This is found inside the Oculus OpenXR Mobile SDK, which appears to contain a small number of additional resources for OpenXR native development on Oculus Quest hardware
- Download the Oculus OpenXR Mobile SDK
- Extract the zip to a reasonable location, eg (C:\ovr_openxr_mobile_sdk_1.0.13)
- Create an environment variable called OCULUS_OPENXR_MOBILE_SDK and set it to the path to this directory. This will help us configure the build system to use files from here. Do this using the Control Panel UI or use the following command line
Clone the OpenXR SDK Source Repository
There are two repositories on GitHub for the OpenXR SDK. We want the one called OpenXR-SDK-Source since it includes the hello_xr sample application
- Clone or download OpenXR SDK Source from the OpenXR SDK Source GitHub repository to a reasonable location on your local machine
Modify CMakeLists.txt file
Since by default OpenXR is configured to build a standard Android loader (which as of writing does not appear to work with Quest) we need make some local modifications to the build scripts
- Within the OpenXR-SDK-Source directory, open the file \src\CMakeLists.txt
- Replace the line
with
This tells CMake not to build the standard OpenXR Android loader, and to instead import the shared library provided by Oculus that we downloaded in an earlier step. We use the environment variable we set in that step to locate the directory, and we use CMake variables to select the right library based on the current build configuration
Create an Android Studio Project
Create a new Android Studio Project. In the wizard:
- Select the “No Activity” Project Template
- Enter whatever project and package name you want
- In Minimum SDK, select API 24
Link the OpenXR SDK Source project with Gradle
- Right click on the “app” module in the Android studio project and select “Link C++ Project with Gradle”
- For the Build System, select CMake
- For the Project Path, locate and select the CMakeLists.txt at the root level of the Open-SDK-Source repository that we cloned in the earlier step
Modify build.gradle file
- Open the build.gradle file for the “app” module. Within the Android Studio Project directory, it should be under app\build.gradle
- Inside the android->defaultConfig block, add the block
This tells the build system to only build for the two Application Binary Interfaces that we have loaders for
Build the Application
At this point you should be able to build through Android Studio without any errors, though we still need to make some more changes before we can run the application on the device.
Modify the AndroidManifest.xml
- Replace the AndroidManifest.xml in the AndroidStudio project with the one provided in the OpenXR-SDK-Source/ repository.
- The one in the Android Studio project directory should be under app\src\main\AndroidManifest.xml, and the one in the Open-SDK-Source directory should be under OpenXR-SDK-Source\src\tests\hello_xr\AndroidManifest.xml
- In the newly replaced AndroidManifest.xml file, change the block
to
Specify the Graphics Plugin
Before running, we have to specify the graphics plugin to use by running one of the following commands:
adb shell setprop debug.xr.graphicsPlugin OpenGLES
adb shell setprop debug.xr.graphicsPlugin Vulkan
Run the Application
Congratulations! You should now be able to run the hello_xr sample application on Quest and Quest 2 hardware. If everything worked, you should see a set of colorful cubes around the place as well as cubes attached to your controllers.