自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
OEM 设计令牌
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
OEM 设计令牌是 Material Design 系统的 Android Automotive OS (AAOS) 实现。与移动设备上令牌值的算法或用户选择方法不同,OEM 会指定设计令牌值。设计令牌表示重复的小设计决策,它们构成了设计系统的外观样式,并将静态值替换为不言自明的名称。令牌类似于 Material Design 系统所定义的令牌。
OEM 令牌库
OEM 设计令牌通过 OEM 令牌库加以引用,该库由三个组件组成,如图 1 所示。

图 1. OEM 令牌库组件。
静态库
OEM 令牌库的静态库组件便于访问令牌值,如下所示。
- 提供 API 来访问 OEM 令牌值。
- 支持选择使用 OEM 值替换主题中的令牌引用。
共享库
共享库组件负责定义以下内容:
- 库名称。
- 用于选择启用 OEM 令牌值的布尔值。
- 用于提供 OEM 令牌值的样式。
如需调整此共享库组件(包括 OEM 定义的软件包名称)的 OEM 所有权,OEM 可以创建共享库实现的替换。

图 2. 替换共享库实现。
OEM 共享库
通过为 OEM 提供一种设置软件包名称和签名的途径,共享库的实现则保留不变,OEM 可以替换共享库组件,获得库的 OEM 所有权,同时与 OEM 令牌库中的其他组件保持兼容。
共享库的替换的定义如下所示:
override_android_app {
name: "[OEM]-token-shared-lib",
base: "token-shared-lib",
package_name: "com.[OEM].sharedlib",
rename_resources_package: false,
certificate: …
}
如需设置令牌值,请参阅指定 OEM 令牌值。
OEM 共享库自定义
如需支持不同的令牌值方案(例如,模型或驾车模式区分),OEM 可以通过运行时资源叠加层 (RRO) 定位 OEM 共享库,为令牌提供动态值。如需了解详情,请参阅在运行时更改应用资源的值。
如需设置令牌值,请参阅指定 OEM 令牌值。
指定 OEM 令牌值
如需指定令牌值,请在样式 OemStyle
中将相应的属性设置为所需的值。
<resources>
<style name="OemStyle">
<item name="colorPrimary">#B0C5FF</item>
<item name="colorOnPrimary">#002B76</item>
<item name="colorPrimaryContainer">#003FA4</item>
<item name="colorOnPrimaryContainer">#D9E2FF</item>
…
</style>
</resources>
自选 OEM 值
如果应用要访问 OEM 提供的令牌值,OEM 必须先通过将 enable_oem_tokens
布尔值配置为 true
,来选择替换默认令牌值。
RRO 令牌值
与在 OemStyle
中设置令牌值的方式类似,RRO 可用于修改样式,以提供替代令牌值。
<resources>
<style name="OemStyle">
<item name="com.android.oem.tokens:colorPrimary">#B0C5FF</item>
<item name="com.android.oem.tokens:colorOnPrimary">#002B76</item>
<item name="com.android.oem.tokens:colorPrimaryContainer">#003FA4</item>
<item name="com.android.oem.tokens:colorOnPrimaryContainer">#D9E2FF</item>
…
</style>
</resources>
RRO 应通过指定共享库名称来设置样式中的共享库属性。
如果系统包含令牌共享库的 OEM 实现,则必须将系统配置为在应用类后加载共享库。为此,请在系统的 config_sharedLibrariesLoadedAfterApp
配置中添加库名称 (com.android.oem.tokens
)。如果您有权访问 Google 汽车服务 (GAS),系统会强制执行该要求。
<!-- The OEM token shared library will be loaded after app classes -->
<string-array name="config_sharedLibrariesLoadedAfterApp" translatable="false">
<item>com.android.oem.tokens</item>
</string-array>
最佳做法
下文介绍了 OEM 令牌库的最佳实践。
启用灵活的更新策略
请参阅以下策略,确保灵活更新。
OEM 共享库
由于系统映像需要预安装系统共享库,因此设备必须附带该库,或者在无线下载 (OTA) 更新(如需了解详情,请参阅 OTA 更新)过程中添加此库。不过,在系统映像上添加 OEM 令牌共享库的 OEM 替换的存根实现,有助于日后将完整工作实现的更新推送到设备,而无需进行 OTA。
共享库 RRO
虽然不要求将 RRO 作为系统应用进行安装,但这样做可以提供符合预期的更新行为。
- 系统会在用户未登录时,自动更新应用。
- 用户无法卸载(用户只能卸载更新)。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-08。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-08。"],[],[],null,["# OEM design tokens are an Android Automotive OS (AAOS) implementation of the\n[Material Design](https://m3.material.io/foundations/design-tokens/overview)\nsystem. Unlike the algorithmic or user selection approach for token values on mobile, OEMs designate\ndesign token values. Design tokens represent the small, repeated design decisions that make up a\ndesign system's visual style and replace static values with self-explanatory names. Tokens are\nanalogous to those defined by the Material Design system.\n\nOEM token library\n-----------------\n\nOEM design tokens are referenced through the OEM token library, which consists of the three\ncomponents illustrated in Figure 1.\n\n**Figure 1.** OEM token library components.\n\n### Static library\n\nThe static library component of the OEM token library facilitates access to token values as\nfollows.\n\n- Provides APIs to access OEM values for tokens.\n- Enables opt-in overriding of token references in theme with OEM values.\n\n### Shared library\n\nThe shared library component is responsible for defining the following:\n\n- Library name.\n- Boolean opt-in for enabling for OEM token values.\n- Style that provides OEM token values.\n\nTo accommodate OEM ownership of this shared library component, including an OEM-defined package\nname, OEMs can create an override of the shared library implementation.\n\n**Figure 2.** Override a shared library implementation.\n\n### OEM shared library\n\nOEM overrides of the shared library component allow for OEM ownership of the library while\nmaintaining compatibility with other components in the OEM token library by providing a means for\nthe package name and signature to be set by OEMs while leaving implementation of the shared\nlibrary otherwise unmodified.\n\nOverrides for a shared library can be defined as shown below: \n\n```transact-sql\noverride_android_app {\n name: \"[OEM]-token-shared-lib\",\n base: \"token-shared-lib\",\n package_name: \"com.[OEM].sharedlib\",\n rename_resources_package: false,\n certificate: ...\n}\n```\n\nTo set token values, see [Specify OEM token values](#token-values).\n| **Important:**Shared libraries MUST be preinstalled on a system image.\n\n### OEM shared library customizations\n\nTo support varied schemes for token values (for example, model or drive mode differentiation),\nOEMs can provide dynamic values for tokens by targeting the OEM shared library with Runtime\nResource Overlays (RROs). To learn more, see\n[Change the value of an app's resources at runtime](/docs/core/runtime/rros).\n\nTo set token values, see [Specify OEM token values](#token-values).\n\nSpecify OEM token values\n------------------------\n\nTo specify token values, set the corresponding attribute in the style `OemStyle` to\nthe required value. \n\n```text\n\u003cresources\u003e\n \u003cstyle name=\"OemStyle\"\u003e\n \u003citem name=\"colorPrimary\"\u003e#B0C5FF\u003c/item\u003e\n \u003citem name=\"colorOnPrimary\"\u003e#002B76\u003c/item\u003e\n \u003citem name=\"colorPrimaryContainer\"\u003e#003FA4\u003c/item\u003e\n \u003citem name=\"colorOnPrimaryContainer\"\u003e#D9E2FF\u003c/item\u003e\n …\n \u003c/style\u003e\n\u003c/resources\u003e\n```\n\n### Opt in to OEM values\n\nSo that apps can access OEM-provided token values, OEMs must first opt in to overriding default\ntoken values by configuring the `enable_oem_tokens` boolean to be `true`.\n\n### RRO token values\n\nSimilarly to how token values are set in `OemStyle`, RROs can be used to modify the\nstyle to provide alternate token values. \n\n```text\n\u003cresources\u003e\n \u003cstyle name=\"OemStyle\"\u003e\n \u003citem name=\"com.android.oem.tokens:colorPrimary\"\u003e#B0C5FF\u003c/item\u003e\n \u003citem name=\"com.android.oem.tokens:colorOnPrimary\"\u003e#002B76\u003c/item\u003e\n \u003citem name=\"com.android.oem.tokens:colorPrimaryContainer\"\u003e#003FA4\u003c/item\u003e\n \u003citem name=\"com.android.oem.tokens:colorOnPrimaryContainer\"\u003e#D9E2FF\u003c/item\u003e\n …\n \u003c/style\u003e\n\u003c/resources\u003e\n```\n\nRROs should set the shared library attributes on the style by specifying the shared library\nname.\n\nConfigure load last\n-------------------\n\nSystems that include an OEM implementation of a token shared library must configure the system\nto load the shared library after the app classes. To do so, include the library name\n(`com.android.oem.tokens`) in the `config_sharedLibrariesLoadedAfterApp`\nconfig on the system. If you have access to Google Automotive Services (GAS), this is enforced as a\nrequirement. \n\n```\n\u003c!-- The OEM token shared library will be loaded after app classes --\u003e\n\u003cstring-array name=\"config_sharedLibrariesLoadedAfterApp\" translatable=\"false\"\u003e\n \u003citem\u003ecom.android.oem.tokens\u003c/item\u003e\n\u003c/string-array\u003e\n```\n\nBest practices\n--------------\n\nBest practices for the OEM token library are described below.\n\n### Enable a flexible update strategy\n\nSee the strategies below to ensure you build in flexibility with respect to updates.\n\n#### OEM shared library\n\nAs system-shared libraries are required to be preinstalled on system images, devices must either\nship with the library or the library must be added as part of an Over-the-Air (OTA) update (to learn\nmore, see [OTA Updates](/docs/core/ota)).\nHowever, including a stub implementation of an OEM override of an OEM token shared library on a\nsystem image allows for an update to a full working implementation to be pushed to devices at a\nlater date without necessitating an OTA.\n\n#### Shared library RROs\n\nAlthough there is no requirement for RROs to be installed as system apps, doing so provides some\nupdate behavior that might be desired.\n\n- Automatic updates of apps when users aren't signed in.\n- Can't be uninstalled by the user (users can only **uninstall updates**)."]]