基礎知識
デバイスが3種類
- XR ヘッドセット
- 有線 XR グラス
- AI メガネ(AI グラス
ざっくり、「XRヘッドセットは完全没入型、有線XRグラスは現実に重ねる拡張表現、AIメガネは軽量で常時着用な目と耳をAIで拡張するデバイス」とまとめられそう
開発ツールはさまざま、種類によって指定あり
使える開発ツールの分類は「XR ヘッドセット,有線 XR グラス」と「AI メガネ」でざっくり分けられている。
前者はUnity,OpenXR等サポートしているが、Jetpack XR SDKがアプリ開発者的には標準となりそう。
後者のAIメガネは Jetpack XR SDK と Jetpack Compose Glimmer を使う。
「XR ヘッドセット,有線 XR グラス」には モードが二つある
- ホームスペースとフルスペース
ホームスペース
リリース済みのモバイルアプリがデフォルトで表示されるのもここ、大画面のモバイルアプリ
複数のアプリでマルチタスク
フルスペース
フルスペースは一つのアプリ
既存のアプリも空間化できる
3Dモデルの描画等はこのモードのみ
サンプル
https://github.com/android/xr-samples
サンプルで違いを確認するとイメージしやすい
AI メガネは日常生活との統合が優先
一言で表現すると「現実と競合せず、必要な瞬間だけ短くわかりやすく伝えるUIUX」が求められてそう(メガネなのでそうれはそうという感じ)
構成の基礎知識
起動モード
アプリ起動時にホームスペースで開くか、フルスペースで開くかをマニフェストで宣言する。特に指定がないとHomeSpaceだった
Home
<property
android:name="android.window.PROPERTY_XR_ACTIVITY_START_MODE"
android:value="XR_ACTIVITY_START_MODE_HOME_SPACE_MANAGED" />
Full
<property
android:name="android.window.PROPERTY_XR_ACTIVITY_START_MODE"
android:value="XR_ACTIVITY_START_MODE_FULL_SPACE_MANAGED" />
リリース周り
モバイルリリーストラックまたは Android XR 専用のリリーストラック に配信可能
モバイルリリーストラック
- モバイルリリーストラックにすでに配信済みのアプリがある場合は,サポート外機能がない限りXRのPlayStoreからDL可能。ホームスペースで使用できる
- Jetpack XR SDK を使用したアプリをモバイルリリーストラックに公開する場合は以下の設定が必要
<uses-feature android:name="android.software.xr.api.spatial" android:required="false" />
- XR向けに公開したくない場合は、デバイスカタログからデバイス除外する
Android XR 専用トラック
- XR デバイス専用アプリはこのトラックに公開
- Jetpack XR SDK でビルドされている場合は以下設定
<uses-feature android:name="android.software.xr.api.spatial" android:required="true" />
- OpenXR または Unity でビルドされている場合はandroid.software.xr.api.openxr を正しく設定する
品質ガイドライン
以下三つのTierがある
- XR対応をモバイルアプリ
- XR 対応の大画面アプリ
- XR の差別化されたアプリ
Jetpack XR SDK の基本的なところ
HomeSpaceはただの大画面対応スマホアプリ。FullSpaceを前提に見ていきます。
FULLSPACEになっているかどうか
LocalSpatialCapabilities.current.isSpatialUiEnabled
- isSpatialUiEnabled: アプリケーションが空間 UI 要素(SpatialPanel など)を作成できるかどうか
- SpecialじゃなくてSpatial(空間的)
if (LocalSpatialCapabilities.current.isSpatialUiEnabled) {
// 空間UI
} else {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text("Not Supported")
}
}
XR_ACTIVITY_START_MODE_HOME_SPACE_MANAGEDで起動。Not SupportedのText側が表示され、Homeなので複数のアプリと同時に表示できる。

XR_ACTIVITY_START_MODE_FULL_SPACE_MANAGEDで起動。空間UIが表示される。

Subspace
FullSpaceで空間コンテンツを描画するのに必須
3D コンテンツの配置、3D レイアウトの構築、2D コンテンツへの奥行き追加ができるようになります
サブスペースは、空間化が有効になっている場合にのみレンダリングされます。ホームスペースまたは非 XR デバイスでは、そのサブスペース内のコードはすべて無視されます
@SubspaceComposable を使って3D要素を描画するためのコンテナ、空間レイアウトはこのSubspace下に配置する必要がある。
@Composable
@ComposableOpenTarget(index = -1)
@Suppress("COMPOSE_APPLIER_CALL_MISMATCH") // b/446706254
public fun Subspace(
modifier: SubspaceModifier = SubspaceModifier,
allowUnboundedSubspace: Boolean = false,
content: @Composable @SubspaceComposable SpatialBoxScope.() -> Unit,
)
後述の空間レイアウトを Composableツリーの祖先でSubSpaceを宣言していない場合は例外
/*
NG : java.lang.IllegalStateException: SubspaceComposable functions are expected to be used within the context of a Subspace composition.
Please ensure that this component is in a Subspace or is a child of another SubspaceComposable.
*/
setContent {
if (LocalSpatialCapabilities.current.isSpatialUiEnabled) {
SpatialRow() {...} // 空間レイアウト
}
}
// OK
setContent {
if (LocalSpatialCapabilities.current.isSpatialUiEnabled) {
Subspace {
SpatialRow() {...} // 空間レイアウト
}
}
}
またallowUnboundedSubspace をtrueにすると、推奨サイズを無視できる。SubspaceModifierでsizeを指定する必要あり。基本はfalseでよいはず
// java.lang.IllegalStateException: SubspaceComposable functions are expected to be used within the context of a Subspace composition. Please ensure that this component is in a Subspace or is a child of another SubspaceComposable.
Subspace(
allowUnboundedSubspace = true
) {}
SubSpaceは基本的にアプリレベルや画面レベルで宣言となりそう
最上位の Subspace は、アプリによって呼び出される最も外側のサブスペースです。Subspace の呼び出しごとに、新しい独立した空間 UI 階層が作成されます。
SubspaceModifier
位置決め、回転、動作の追加が可能になります
デフォルトだと親いっぱいに広がる
Subspace {
SpatialRow(
modifier = SubspaceModifier
)
depthは3Dオブジェクトの深さ描画に関与?
SpatialPane
- Panelごとに自由に空間配置ができるコンポーネント
- MovePolicy , ResizePolicy で ポリシーを変えられる
Paneは動かしたり、広げたりできるコンテナと言える
Subspace {
SpatialRow(
modifier = SubspaceModifier
.height(800.dp)
) {
// List側
SpatialPanel(
SubspaceModifier
.width(240.dp)
.fillMaxHeight(),
dragPolicy = MovePolicy(isEnabled = true),
resizePolicy = ResizePolicy(isEnabled = true)
) {...}
// Detail Panel: 残りの領域
SpatialPanel(
modifier = SubspaceModifier
.fillMaxSize()
.padding(left = 16.dp),
dragPolicy = MovePolicy(isEnabled = true),
resizePolicy = ResizePolicy(isEnabled = true)
) {...}
パネル内はRowやColumnの他Boxなどで部品配置する
SpatialRow、SpatialColumn、SpatialBox、SpatialLayoutSpacer
Orbiter
- 言葉の原意は天体のまわりを周回する物体のこと
- パネル(やコンポーネント)に紐づけるコンポーネントで、紐づけたパネルに対してなんらかのアクションを設定するもの
- 基本的にPanelのサイズが尊重される。これ自体は SubspaceComposableではなく普通のComposable
上述の画像のアイコンおいているコンポーネントはOrbiter
SpatialPanel(
SubspaceModifier
.width(240.dp)
.fillMaxHeight(),
dragPolicy = MovePolicy(isEnabled = true),
resizePolicy = ResizePolicy(isEnabled = true)
) {
Column {
Orbiter(
position = ContentEdge.Top,
offset = 8.dp,
offsetType = OrbiterOffsetType.InnerEdge,
shape = SpatialRoundedCornerShape(size = CornerSize(50))
) {
Surface(
modifier = Modifier.fillMaxWidth().padding(start = 12.dp)
){
Row (
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier
.fillMaxWidth()
.height(60.dp)
.padding(vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically
) {
IconButton(onClick = { /* TODO: Implement add memo logic */ }) {
Icon(
imageVector = Icons.Default.Add,
contentDescription = "Add Memo"
)
}
IconButton(onClick = { /* TODO: Implement add memo logic */ }) {
Icon(
imageVector = Icons.Default.Search,
contentDescription = "Add Search"
)
}
IconButton(onClick = { /* TODO: Implement add memo logic */ }) {
Icon(
imageVector = Icons.Default.Edit,
contentDescription = "Add Edit"
)
}
}
}
}
Surface(
modifier = Modifier.fillMaxSize().padding(start = 12.dp),
shape = RoundedCornerShape(8.dp),
) {
MemoList(
memos = listUiState.memos,
selectedId = selectedMemoId,
onMemoSelected = { id -> selectedMemoId = id }
)
}
}
}
Material Design
ここまで作ったものは Material のCanonical Layout で置き換え可能(というより、これで作るのがたぶん正しい)
https://developer.android.com/develop/xr/jetpack-xr-sdk/material-design?hl=ja
コード
import androidx.xr.compose.material3.NavigationSuiteScaffold
import androidx.xr.compose.material3.EnableXrComponentOverrides
import androidx.compose.material3.adaptive.navigation.NavigableListDetailPaneScaffold
...
Subspace {
NavigationSuiteScaffold(
navigationSuiteItems = {
item(
selected = true,
icon = {
Icon(imageVector = Icons.Default.Add,contentDescription = "Add Memo")
},
onClick = {}
)
item(
selected = true,
icon = {
Icon(imageVector = Icons.Default.Search,contentDescription = "Search Memo"
)
},
onClick = {}
)
item(
selected = true,
icon = {
Icon(imageVector = Icons.Default.Edit,contentDescription = "Edit Memo")
},
onClick = {}
)
},
modifier = SubspaceModifier,
layoutType = NavigationSuiteType.NavigationRail
) {
EnableXrComponentOverrides {
NavigableListDetailPaneScaffold(
navigator = navigator,
listPane = {
AnimatedPane(modifier = Modifier) {
Surface(Modifier.fillMaxSize()) {
MemoListContent(
memos = filteredMemos,
selectedId = selectedMemoId,
onMemoSelected = { id ->
scope.launch {
navigator.navigateTo(
pane = ListDetailPaneScaffoldRole.Detail,
contentKey = id
)
}
}
)
}
}
},
detailPane = {
AnimatedPane(modifier = Modifier) {
navigator.currentDestination?.contentKey?.let {
MemoDetailContent(memo = detailUiState.memo)
}
}
}
)
}
}
}
ライブラリ
- androidx.xr.compose.material3 で xr用が用意されている
- EnableXrComponentOverridesで androidx.compose.material3 をXR用に転用できる。上述のコード例のように、adaptive系のnavigation部品は転用しちゃうのが今の所楽
- NavigationRailやNavigationBarはandroidx.xr.compose.material3に含まれているが,依存しているNavigationSuiteTypeが androidx.compose.material3.adaptiveのものなのでそちらの依存も必要
終わり
3D周りはまた別途






