This guide explains how Horizon OS SDK versioning works and how your application can use this mechanism effectively.
Specifically, you will learn:
How Horizon OS and Horizon OS SDK are versioned
How your application can integrate the uses-horizonos-sdk manifest element
How to support multiple Horizon OS versions by adjusting your application’s behavior at runtime
Version numbering in Horizon OS SDK and Horizon OS
Each release of the Horizon OS SDK is assigned an integer version number, such as 203. This value is conceptually equivalent to Android’s API level, but Horizon OS SDK version numbers are independent of the API level of the Android Open Source Project (AOSP) version upon which Horizon OS is based. This value increases with each release that is not a patch to a previously released version. Version numbers may be skipped.
A separate, user-facing version string for Horizon OS is visible to users via user interfaces on Quest devices and on other software such as the Meta Horizon mobile app, the Meta Horizon Link app, and the Meta Quest Developer Hub. This user-facing Horizon OS version uses semantic versioning, such as 2.1. Although this value can be queried via Horizon OS SDK, do not reference it for the purposes described in this guide. This API should only be used for situations where the user-facing version number of Horizon OS is relevant, such as in your app’s telemetry. See API reference documentation for more information.
Versioning in your package’s manifest
The uses-horizonos-sdk element
Meta Horizon OS supports an XML element, uses-horizonos-sdk, for inclusion in your application’s AndroidManifest.xml file. Similar to the Android uses-sdk element, including this element in your application increases your application’s stability and compatibility across Horizon OS versions.
For now, including this element in your app’s manifest is optional.
Adding the uses-horizonos-sdk element to your manifest
The uses-horizonos-sdk manifest element lets you control your package’s distribution and Horizon OS behavior related to your package.
To add this element to your package, make two changes in your AndroidManifest.xml file:
Within the root <manifest> element, add the following XML namespace attribute: xmlns:horizonos="http://schemas.horizonos/sdk".
Within the <manifest> element, add the <uses-horizonos-sdk> element and specify values for the minSdkVersion and targetSdkVersion attributes.
Here’s an example of what your updated manifest should look like.
The minSdkVersion attribute specifies the minimum Horizon OS SDK version that your application is compatible with.
When Horizon OS installs a package, the package’s specified minSdkVersion is compared to the Horizon OS SDK version available on the OS. If minSdkVersion is greater than the Horizon OS SDK version present, installation is blocked. Additionally, the package may be filtered out of Store searches or other user interfaces on devices running a version of Horizon OS with which the app is not compatible.
Choosing a minSdkVersion
To select an appropriate minSdkVersion, evaluate which Horizon OS SDK version your application is compatible with, and which Horizon OS versions you intend to support.
Consider the following:
What is the first Horizon OS SDK version that contains all APIs your application depends on?
Does your application depend on components, such as libraries, that have their own minSdkVersion requirements?
Across what range of Horizon OS versions do you intend to support your users?
While you’ll need to choose the value that best fits your application, common approaches include:
Set minSdkVersion to the Horizon OS SDK version used in development, both in your project and on your device. This ensures your application will not run on older Horizon OS versions.
Set minSdkVersion to the first Horizon OS SDK version containing all APIs used directly by your application. This enables targeting a wider range of Horizon OS versions while ensuring your application does not invoke APIs that do not exist on the running OS version.
Set minSdkVersion to the lowest Horizon OS SDK version you can support, even though older versions lack some APIs your application references. At runtime, invoke only APIs available in the Horizon OS SDK version reported by the version query APIs. This approach maximizes compatibility with older Horizon OS versions.
The targetSdkVersion attribute
The targetSdkVersion attribute specifies the Horizon OS SDK version your application targets.
Horizon OS behavior evolves with each release. To maximize compatibility with existing applications, wherever possible, changes to OS behavior apply only to clients built to be compatible with those new behaviors. For clients targeting older SDK versions, compatibility behaviors consistent with the specified targetSdkVersion are executed instead.
Choosing a targetSdkVersion
To select targetSdkVersion, evaluate which Horizon OS behavior version your application prefers and which Horizon OS SDK version your application was tested against.
For most applications, update targetSdkVersion frequently to take advantage of the latest Horizon OS advances. In rare cases, an older targetSdkVersion is preferred, such as when your application depends on legacy Horizon OS behavior that no longer works the same way in more recent SDK versions.
Adjusting your application’s behavior at runtime
To support multiple Horizon OS SDK versions simultaneously, query the Horizon OS SDK version available at runtime and adjust your application’s behavior accordingly. APIs for querying the available Horizon OS SDK version are available through Horizon OS SDK via Horizon OS JSDK and NSDK. A related utility API in Horizon OS Support Library is also provided (see Handling versioning with Horizon OS Support Library).
This is optional. It is not relevant if your application targets a single Horizon OS SDK version, such as the most recent one. However, if you want to target multiple Horizon OS SDK versions, this mechanism maximizes compatibility.
For example, if an API your application requires has been deprecated and replaced with a new API, your application should invoke the new API on Horizon OS versions that support it and fall back to the deprecated API otherwise.
Similarly, if Horizon OS behavior has evolved in a way that affects your application, your application should include behaviors that are compatible with the old and new Horizon OS behavior, and select the correct behavior at runtime based on the Horizon OS SDK version
The following pseudocode demonstrates a typical pattern for supporting both a deprecated API and its replacement when supporting Horizon OS versions before and after the replacement API was introduced.
int first_sdk_version_with_new_api = ...
if get_horizon_os_sdk_version() < first_sdk_version_with_new_api
then call_deprecated_api()
else call_new_api()
Handling versioning with Horizon OS Support Library
An alternative to direct integration with Horizon OS SDK APIs is to use the Horizon OS Support Library. This will ensure your code is backwards compatible and in the best position to receive updates should the calling patterns evolve. The Horizon OS Support Library is currently only available for clients capable of calling Java APIs (for example, Java and Kotlin).
Get the library
The Horizon OS Support Library is distributed through Maven Central and can be added to your Gradle build just like other dependencies of this type:
The Horizon OS Support Library can coexist in a project alongside other Horizon OS SDKs.
Perform the check
Once the Horizon OS Support library has been added as a dependency, you can use the HorizonOsSdkVersion.isAtOrAbove() method to determine the Horizon OS version on which your app is running.
import horizonosx.os.HorizonOsSdkVersion
if (HorizonOsSdkVersion.isAtOrAbove(200)) {
// execute code that only works on Horizon OS version 200 or later
} else {
// fall back to default behavior if APIs are not available
}
Java is a registered trademark of Oracle and/or its affiliates.