Get started with the Jetpack XR SDK

This guide provides instructions for creating an Android XR application using the Jetpack XR SDK. It covers essential dependencies and project setup in Android Studio for building immersive XR experiences.

Compatibility

The Jetpack XR SDK requires a minSdk of 24 and must compile to SDK 34 or higher.

Add dependencies

See the following reference guides to understand necessary dependencies and compatibility issues for each of the libraries in the Jetpack XR SDK:

Then, add the necessary dependencies to your app's build.gradle.kts file:

Groovy

dependencies {
    
    // Required for Java
    implementation "com.google.guava:listenablefuture:1.0"
    // Required for Kotlin
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.9.0"

    implementation "androidx.xr.runtime:runtime:1.0.0-alpha05"
    implementation "androidx.xr.scenecore:scenecore:1.0.0-alpha06"
    implementation "androidx.xr.compose:compose:1.0.0-alpha06"
    implementation "androidx.xr.compose.material3:material3:1.0.0-alpha10"
    implementation "androidx.xr.arcore:arcore:1.0.0-alpha05"
}

Kotlin

dependencies {
    
    // Required for Java
    implementation("com.google.guava:listenablefuture:1.0")
    // Required for Kotlin
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.9.0")

    implementation("androidx.xr.runtime:runtime:1.0.0-alpha05")
    implementation("androidx.xr.scenecore:scenecore:1.0.0-alpha06")
    implementation("androidx.xr.compose:compose:1.0.0-alpha06")
    implementation("androidx.xr.compose.material3:material3:1.0.0-alpha10")
    implementation("androidx.xr.arcore:arcore:1.0.0-alpha05")
}

See the Hello Android XR sample.

Enable code minification (optional)

If you want to enable code minification and obfuscation using ProGuard for your builds, you must add a dependency on the Android Extensions for XR library. This is required for projects using Jetpack XR alpha05 or newer.

Add the following compileOnly dependency to your module's build.gradle.kts file:

Groovy

dependencies {
    // ... other dependencies
    compileOnly "com.android.extensions.xr:extensions-xr:1.0.0"
}

Create a new app in Android Studio using the Basic Headset Activity Template

To create a new project that includes Jetpack Compose for XR, proceed as follows:

  1. If you're in the Welcome to Android Studio window, click Start a new Android Studio project. If you already have an Android Studio project open, select File > New from the menu bar.
  2. Select XR from the Template options and then Basic Headset Activity.
  3. In the Configure your project window, do the following:
    1. Set the Application name.
    2. Choose the Project location for your sample.
  4. Click Finish.
  5. Verify that the project's build.gradle file is configured correctly, as described in Gradle properties files.