您可以使用 Android 模拟器来测试您的应用在 Android Automotive OS 上的运行情况。
添加系统映像
在创建 Android Automotive OS 虚拟设备之前,您需要通过 Android Studio SDK 管理器添加系统映像。
添加通用系统映像
Android Studio 包含用于 Android Automotive OS 的通用系统映像,可用于测试您的应用,并且应在为 Google Play 截取屏幕截图时使用这些映像。所有这些映像都包括
- Google Play 服务
- Google 车载应用主机 API 28 映像除外,因为该主机仅在运行 API 29 或更高版本的设备上可用
名称 | API 级别 | 架构 | 功能 | 可用性 |
---|---|---|---|---|
Automotive Intel x86 Atom 系统映像 | 28 | x86 | Google Play 商店 | |
Automotive(带 Play 商店)Intel x86 Atom 系统映像 | 29 | x86 | Google Play 商店 | |
Automotive(带 Play 商店)Intel x86_64 Atom 系统映像 | 30 | x86 | Google Play 商店 | |
Automotive(带 Play 商店)ARM 64 v8a 系统映像 | 32 | ARM | Google Play 商店 | |
Automotive(带 Play 商店)Intel x86_64 Atom 系统映像 | 32 | x86 | Google Play 商店 | |
Automotive Distant Display(带 Google API)arm64-v8a 系统映像 | 32 | ARM | ||
Automotive Distant Display(带 Google API)x86_64 系统映像 | 32 | x86 | ||
Automotive Distant Display(带 Google Play)arm64-v8a 系统映像 | 32 | ARM | Google Play 商店 | |
Automotive Distant Display(带 Google Play)x86_64 系统映像 | 32 | x86 | Google Play 商店 | |
Android Automotive(带 Google API)ARM 64 v8a 系统映像 | 33 | ARM | ||
Android Automotive(带 Google API)Intel x86_64 Atom 系统映像 | 33 | x86 | ||
Automotive Distant Display(带 Google Play)arm64-v8a 系统映像 | 33 | ARM | Google Play 商店 | |
Automotive Distant Display(带 Google Play)x86_64 系统映像 | 33 | x86 | Google Play 商店 | |
Android Automotive(带 Google API)arm64-v8a 系统映像 | 34-ext9 | ARM | ||
Android Automotive(带 Google API)x86_64 系统映像 | 34-ext9 | x86 | ||
Android Automotive(带 Google Play)arm64-v8a 系统映像 | 34-ext9 | ARM | ||
Android Automotive(带 Google Play)x86_64 系统映像 | 34-ext9 | x86 |
按照以下步骤安装通用系统映像
- 在 Android Studio 中,依次选择 Tools > SDK Manager。
- 点击 SDK Platforms 标签页。
- 点击 Show Package Details。
- 选择要下载的映像。有关详细信息,请参阅上表。
点击 Apply,然后点击 OK。
添加 OEM 提供的系统映像
您还可以添加适用于通用汽车、本田、极星、沃尔沃及其他品牌的 OEM 专用系统映像。请按照 OEM 开发者网站上的步骤操作
按字母顺序
创建车载 AVD 并运行模拟器
按照以下步骤创建代表 Android Automotive OS 车辆的 Android 虚拟设备 (AVD),然后使用该 AVD 运行模拟器
- 在 Android Studio 中,依次选择 Tools > AVD Manager。
- 点击 Create Virtual Device。
- 在选择硬件对话框中,选择 Automotive,然后选择一个硬件配置文件。点击 Next。
- 选择面向 Automotive 的系统映像,例如 Android 12L (Automotive with Play Store),然后点击 Next。
- 为您的 AVD 命名并选择您要自定义的任何其他选项,然后点击 Finish。
- 在工具窗口栏中,选择您的 Android Automotive OS AVD 作为部署目标。
- 点击 Run
。
使用捆绑的硬件配置文件
创建 AVD 时,您可以使用 Android Studio 捆绑的以下硬件配置文件
名称 | 分辨率 | 可配置 | 兼容性 | 可用性 |
---|---|---|---|---|
Automotive(1024p 横向) | 1024x768 | |||
Automotive(1080p 横向) | 1080x600 | ✔ | 不带 Google Play 商店的 API 33+ 系统映像 | |
Automotive(1408p 横向) 建议与 API 34 映像一起使用 |
1408x792 | 不带 Google Play 商店的 API 33+ 系统映像 | ||
Automotive(1408p 横向,带 Google Play) 建议与 API 34 映像一起使用 |
1408x792 | |||
Automotive 纵向 | 800x1280 | 不带 Google Play 商店的 API 33+ 系统映像 | ||
Automotive 大纵向 | 1280x1606 | ✔ | 不带 Google Play 商店的 API 33+ 系统映像 | |
Automotive 超宽 | 3904x1320 | ✔ | 不带 Google Play 商店的 API 33+ 系统映像 | |
Automotive 远端显示 | 1080x600 | 不带 Google Play 商店的 API 32+ 远端显示系统映像 | ||
Automotive 远端显示(带 Google Play) | 1080x600 |
创建硬件配置文件
如果您想测试捆绑硬件配置文件中未涵盖的硬件配置,您还可以创建硬件配置文件以用于 Android Automotive OS 模拟器。为此,请在创建流程中选择 Android Automotive 作为设备类型。自定义硬件配置文件仅与不包含 Google Play 商店的系统映像兼容。
使用模拟器的扩展控件
除了其他 Android 模拟器中提供的许多标准扩展控件之外,还有一些专门为 Android Automotive OS 模拟器制作的扩展控件。
模拟硬件状态
除了在可用时可以使用标准 Android API 读取的加速度计和陀螺仪等传感器之外,车辆特有的其他硬件属性通过车辆硬件抽象层 (VHAL) 进行通信。这些属性由 VehiclePropertyIds
类建模。
模拟器运行时,您可以从扩展控件的车辆数据功能中修改这些属性的值。例如,要设置车辆的当前速度,您可以找到速度属性 (VehiclePropertyIds.PERF_VEHICLE_SPEED
) 并更改其值。
模拟驾驶
要模拟驾驶,您应将车速设置为非零值,并将档位设置为除 P(驻车)以外的值。要模拟驻车状态,只需将档位设置为 P(驻车)。这可以通过使用汽车传感器数据标签页下的滑块和选择器来完成,或通过修改上一节中描述的 VHAL 属性来完成。
测试旋转输入
除了触摸屏之外,一些 Android Automotive OS 车辆还配备了旋转控制器,它依赖于与键盘导航相同的焦点 API,让用户无需触摸屏幕即可导航应用。您可以使用扩展控件中的车载旋转器工具来测试您的应用对旋转输入的支持。
编辑媒体应用的运行配置
Automotive OS 上的媒体应用与其他 Android 应用不同。Android Automotive OS 通过显式 intent 并向您的媒体浏览器服务发送调用来与您的媒体应用交互。
要测试您的应用,请验证您的应用在其清单中没有启动 activity,然后通过完成以下步骤来阻止您的车载模块随 activity 启动
在 Android Studio 中,依次选择 Run > Edit Configurations。
从应用模块列表中选择您的车载模块。
在 Launch Options > Launch 下,选择 Nothing。
点击 Apply,然后点击 OK。
报告 Android Automotive OS 模拟器问题
如果您在使用 Android Automotive OS 模拟器时遇到问题或有功能请求,您可以使用 Google 问题跟踪器报告。务必填写问题模板中请求的所有信息。在提交新问题之前,请检查问题列表中是否已报告该问题。您可以通过点击跟踪器中问题旁边的星标来订阅和投票支持问题。如需了解详情,请参阅订阅问题。