Int IDs. Historically these came from Android resource IDs (R.id.*) populated by AAPT2 at the consuming APK's link time — which made the integers unstable across builds and consumers, breaking compiled-AAR distribution.
components directory). The result is packaged into the APK as a name → ID map asset; at process startup the bootstrap reads that asset and calls SpatialIdRegistry.install. Generated component companions then read their IDs eagerly at companion class init via SpatialIdRegistry.component and SpatialIdRegistry.attribute.
Int fields on the companion — accesses are single field reads, with no per-access lazy delegate, no synchronization, and no allocation.
SpatialIdsBootstrap.installIfPresent runs from VrActivity.onCreate and reads the build-time map from assets/spatial_ids.json. If the asset is present, that's the happy path: every lookup returns its build-time-assigned integer.
spatial_id_assign Buck macro / AssignSpatialIdsTask), the registry falls back to handing out IDs from a monotonic counter on first lookup and logs a one-time warning naming the missing component. The app keeps working, but IDs are unstable across runs/builds and across other apps that load components in a different order. Adopt the assigner to fix.
object SpatialIdRegistry
attribute
(
className
, propName
)
|
Looks up the ID for an attribute. Called from generated companion <clinit>. See SpatialIdRegistry.component for the lookup-vs-fallback semantics.
Signature
fun attribute(className: String, propName: String): Int Parameters className: String
the owning component's simple class name.
propName: String
the attribute's name as declared in its XML schema.
Returns Int |
component
(
name
)
|
Looks up the ID for a component class. Called from generated companion <clinit>.
Returns the build-time-assigned integer if SpatialIdRegistry.install has been called and the name is present. Otherwise, falls back to a monotonic counter (see class KDoc).
Signature
fun component(name: String): Int Parameters name: String
the component's simple class name as declared in its XML schema.
Returns Int |
install
(
componentMap
, attributeMap
)
|
Installs the build-time name → ID maps. Called once during process bootstrap before any component companion is touched. Re-installation replaces the previous maps; this supports tests that need to swap fixtures between cases.
Signature
fun install(componentMap: Map<String, Int>, attributeMap: Map<String, Int>) Parameters componentMap: Map
simple component name (e.g. "Named") → assigned ID.
attributeMap: Map "ComponentName.attributeName" → assigned ID.
|
reset
()
|
Test-only: clears the installed maps and the fallback state so a subsequent SpatialIdRegistry.install starts from a clean slate.
Signature
fun reset() |