Add necessary dependencies

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

Example

The following snippet from the Hello Android XR sample shows an example build.gradle file that includes all the Jetpack XR SDK dependencies:

dependencies {
    val composeBom = platform(libs.androidx.compose.bom)
    implementation(composeBom)
    implementation(libs.impress)
    implementation(libs.androidx.arcore)
    implementation(libs.androidx.scenecore)
    implementation(libs.androidx.compose)
    implementation(libs.kotlinx.coroutines.guava)

    implementation(libs.material)
    implementation(libs.androidx.compose.material3)
    implementation(libs.androidx.adaptive.android)
    implementation(libs.androidx.concurrent.futures)
    implementation(libs.androidx.compose.runtime)
    implementation(libs.androidx.activity.compose)

    debugImplementation(libs.androidx.compose.ui.tooling)

    screenshotTestImplementation(libs.androidx.compose.ui.tooling)
}

And here is an example of the corresponding libs.toml file:

[versions]
androidx-runtime = "1.8.0-alpha06"
agp = "8.6.1"
arcore = "1.0.0-alpha01"
compose = "1.0.0-alpha01"
impress = "0.0.1"
kotlinxCoroutinesGuava = "1.9.0"
scenecore = "1.0.0-alpha01"
kotlin = "2.0.21"
concurrentFuturesKtx = "1.2.0"
activityCompose = "1.10.0-beta01"
composeBom = "2024.11.00"
material = "1.12.0"
screenshot = "0.0.1-alpha08"
adaptiveAndroid = "1.0.0"

[libraries]
androidx-arcore = { module = "androidx.xr.arcore:arcore", version.ref = "arcore" }
androidx-compose = { module = "androidx.xr.compose:compose", version.ref = "compose" }
androidx-scenecore = { module = "androidx.xr.scenecore:scenecore", version.ref = "scenecore" }
impress = { module = "com.google.ar:impress", version.ref = "impress" }
kotlinx-coroutines-guava = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-guava", version.ref = "kotlinxCoroutinesGuava" }
androidx-compose-material3 = { module = "androidx.compose.material3:material3" }
material = { module = "com.google.android.material:material", version.ref = "material" }
androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
androidx-concurrent-futures = { module = "androidx.concurrent:concurrent-futures-ktx", version.ref = "concurrentFuturesKtx" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "androidx-runtime" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }

See the Hello Android XR sample.

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.