自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
Cuttlefish:创建自定义设备
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页介绍了如何创建自定义 Cuttlefish 设备。Cuttlefish 包含具有不同外形规格的预定义设备类型,如 AndroidProducts.mk
中所列。除了添加新设备中所述的常规设备自定义选项之外,您还可以进行特定于 Cuttlefish 的自定义设置,例如虚拟设备板配置预设(vsoc_x86_64、vsoc_arm64、vsoc_riscv64)、内核预构建、引导加载程序预构建、供应商属性、系统配置、嵌套虚拟化支持和显示选项。如需查看可自定义的构建时参数的完整列表,请参阅 device/google/cuttlefish/vsoc_x86_64/phone/aosp_cf.mk
。
以下步骤介绍了如何创建一个虚构的 x86-64 big_phone
设备,大小为普通 Cuttlefish 设备的十倍。
沿用现有目标
要沿用现有目标,请执行以下操作:
- 创建一个
device/google/cuttlefish/vsoc_x86_64/big_phone
目录。
- 在该目录中创建一个
aosp_cf.mk
文件。
$(call inherit-product, device/google/cuttlefish/vsoc_x86_64_phone.mk)
PRODUCT_NAME: big_phone
PRODUCT_DEVICE: vsoc_x86_64
PRODUCT_MANUFACTURER := My Company
PRODUCT_MODEL: My Company very large phone
PRODUCT_VENDOR_PROPERTIES += \
ro.soc.manufacturer=$(PRODUCT_MANUFACTURER) \
ro.soc.model=$(PRODUCT_DEVICE)
添加启动目标
将 lunch
目标插入 device/google/cuttlefish/AndroidProducts.mk
文件中:
PRODUCT_MAKEFILES := \
...
big_phone:$(LOCAL_DIR)/vsoc_x86_64/big_phone/aosp_cf.mk
...
lunch big_phone
定义 JSON 配置
如需启动 Cuttlefish 设备,请创建一个名为 big_phone.json
的 JSON 配置文件,具有表示设备属性的分层结构。例如,在 JSON 配置文件中,您可以指定选项,例如为虚拟机分配的 RAM 和显示配置。此文件不必位于 AOSP 树中。
如需详细了解配置的 JSON 格式,请参阅规范配置。
{
"instances":
[
{
"vm": {
"memory_mb": 40960,
},
"graphics": {
"displays": [
{
"width": 7200,
"height": 12800,
"dpi": 320
}
]
}
}
]
}
如需启动配置,请运行以下命令:
cvd create --config_file=big_phone.json
运行 launch_cvd(旧版)
某些配置属性不支持分层 JSON 配置格式。对于此类配置,您可以设置单级 JSON 字典中的 launch_cvd
标志默认值。如需查看所有配置选项的完整列表,请参阅 cf_flags_validator.cpp
。
以下示例说明了如何使用 JSON 配置文件替换 launch_cvd
标志选项的默认值,并让 Cuttlefish 启动器启动自定义配置。
创建带有自定义值的 JSON 配置文件 device/google/cuttlefish/shared/config/config_big_phone.json
。
{
"x_res": 7200,
"y_res": 12800,
"dpi": 320,
"memory_mb": 40960,
"ddr_mem_mb": 49150,
}
如需让 Cuttlefish 启动器启动 big_phone
配置,请确保它有权访问 device/google/cuttlefish/shared/config/config_big_phone.json
文件,具体操作步骤如下:
通过在 device/google/cuttlefish/shared/config/Android.bp
文件中添加 prebuilt_etc_host
节,将 JSON 工件声明为 build 工件。
prebuilt_etc_host {
name: "cvd_config_big_phone.json",
src: "config_big_phone.json",
sub_dir: "cvd_config",
}
在 device/google/cuttlefish/shared/device.mk
中运行以下命令,将生成的 build 工件声明添加到 Cuttlefish 启动器。
$(call soong_config_append,cvd,launch_configs,cvd_config_big_phone)
创建 android_info.txt
文件,并将 big_phone
配置与该文件相关联,方法是将以下行添加到 device/google/cuttlefish/vsoc_x86_64/big_phone/aosp_cf.mk
:
TARGET_BOARD_INFO_FILE := device/google/cuttlefish/vsoc_x86_64/<var>big_phone</var>/android-info.txt
通过在 device/google/cuttlefish/vsoc_x86_64/big_phone/android-info.txt
中填充以下代码,为设备类型添加 big_phone
配置标签:
config=big_phone
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Cuttlefish: Create a custom device\n\nThis page describes how to create a customized Cuttlefish device. Cuttlefish\nincludes predefined device types in different form factors as listed in\n[`AndroidProducts.mk`](https://cs.android.com/android/platform/superproject/+/android-latest-release:device/google/cuttlefish/AndroidProducts.mk). In addition to the general device customization\noptions described in\n[Adding a new device](/docs/setup/create/new-device), you can make\nCuttlefish-specific customizations such as virtual device board\nconfiguration presets (vsoc_x86_64, vsoc_arm64, vsoc_riscv64), kernel prebuilts,\nbootloader prebuilts, vendor properties, system configurations, nested\nvirtualization support, and display options. For a full list of the\nbuild time parameters that can be customized, see\n[`device/google/cuttlefish/vsoc_x86_64/phone/aosp_cf.mk`](https://cs.android.com/android/platform/superproject/+/android-latest-release:device/google/cuttlefish/vsoc_x86_64/phone/aosp_cf.mk).\n\nThe following steps describe how to create a fictional x86-64\n\u003cvar translate=\"no\"\u003ebig_phone\u003c/var\u003e device ten times the size of an ordinary\nCuttlefish device.\n\nInherit from an existing target\n-------------------------------\n\nTo inherit from an existing target:\n\n- Create a `device/google/cuttlefish/vsoc_x86_64/`\u003cvar translate=\"no\"\u003ebig_phone\u003c/var\u003e directory.\n- Create an `aosp_cf.mk` file in that directory.\n\n $(call inherit-product, device/google/cuttlefish/vsoc_x86_64_phone.mk)\n\n PRODUCT_NAME: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003ebig_phone\u003c/span\u003e\u003c/var\u003e\n PRODUCT_DEVICE: vsoc_x86_64\n PRODUCT_MANUFACTURER := \u003cvar translate=\"no\"\u003eMy\u003cspan class=\"devsite-syntax-w\"\u003e \u003c/span\u003eCompany\u003c/var\u003e\n PRODUCT_MODEL: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eMy\u003c/span\u003e \u003cspan class=\"devsite-syntax-n\"\u003eCompany\u003c/span\u003e \u003cspan class=\"devsite-syntax-n\"\u003every\u003c/span\u003e \u003cspan class=\"devsite-syntax-n\"\u003elarge\u003c/span\u003e \u003cspan class=\"devsite-syntax-n\"\u003ephone\u003c/span\u003e\u003c/var\u003e\n\n PRODUCT_VENDOR_PROPERTIES += \\\n ro.soc.manufacturer=$(PRODUCT_MANUFACTURER) \\\n ro.soc.model=$(PRODUCT_DEVICE)\n\nAdd a lunch target\n------------------\n\nInsert the `lunch` target into the\n`device/google/cuttlefish/AndroidProducts.mk` file: \n\n PRODUCT_MAKEFILES := \\\n ...\n \u003cvar translate=\"no\"\u003ebig_phone\u003c/var\u003e:$(LOCAL_DIR)/vsoc_x86_64/\u003cvar translate=\"no\"\u003ebig_phone\u003c/var\u003e/aosp_cf.mk\n ...\n\n lunch \u003cvar translate=\"no\"\u003ebig_phone\u003c/var\u003e\n\nDefine JSON configuration\n-------------------------\n\nTo launch the Cuttlefish device, create a JSON configuration file named\n\u003cvar translate=\"no\"\u003ebig_phone\u003c/var\u003e`.json` with a hierarchical structure representing\nthe device properties. For example, in the JSON configuration file, you can\nspecify options such as the RAM allocated for the VM and the display\nconfiguration. This file doesn't have to be in the AOSP tree.\nFor details on the JSON format for configurations, see\n[Canonical configurations](/docs/devices/cuttlefish/multi-tenancy#canonical-configs). \n\n {\n \"instances\":\n [\n {\n \"vm\": {\n \"memory_mb\": 40960,\n },\n \"graphics\": {\n \"displays\": [\n {\n \"width\": 7200,\n \"height\": 12800,\n \"dpi\": 320\n }\n ]\n }\n }\n ]\n }\n\nTo launch the configuration, run: \n\n cvd create --config_file=\u003cvar translate=\"no\"\u003ebig_phone\u003c/var\u003e.json\n\nRun launch_cvd (legacy)\n-----------------------\n\nCertain configuration properties aren't available in the hierarchical JSON\nconfiguration format. For such configurations, you can set `launch_cvd` flag\ndefault values from a single-level JSON dictionary. For a full list of all\nconfiguration options, see\n[`cf_flags_validator.cpp`](https://github.com/google/android-cuttlefish/blob/main/base/cvd/cuttlefish/host/commands/cvd/parser/cf_flags_validator.cpp).\n\nThe following describes an example of how to override the default values of the\n[`launch_cvd` flag options](/docs/devices/cuttlefish/restart#flags)\nusing a JSON configuration file and enable the Cuttlefish launcher to launch the\ncustom configuration.\n\n1. Create a JSON configuration file,\n `device/google/cuttlefish/shared/config/config_`\u003cvar translate=\"no\"\u003ebig_phone\u003c/var\u003e`.json`,\n with custom values.\n\n {\n \"x_res\": 7200,\n \"y_res\": 12800,\n \"dpi\": 320,\n \"memory_mb\": 40960,\n \"ddr_mem_mb\": 49150,\n }\n\n2. For the Cuttlefish launcher to launch the `big_phone` config, ensure it has\n access to the\n `device/google/cuttlefish/shared/config/config_`\u003cvar translate=\"no\"\u003ebig_phone\u003c/var\u003e`.json`\n file by doing the following:\n\n 1. Declare the JSON artifact as a build artifact by adding the\n `prebuilt_etc_host` stanza in the\n `device/google/cuttlefish/shared/config/Android.bp` file.\n\n prebuilt_etc_host {\n name: \"cvd_config_\u003cvar translate=\"no\"\u003ebig_phone\u003c/var\u003e.json\",\n src: \"config_\u003cvar translate=\"no\"\u003ebig_phone\u003c/var\u003e.json\",\n sub_dir: \"cvd_config\",\n }\n\n 2. Add the resulting build artifact declaration into the Cuttlefish\n launcher by running the following in\n `device/google/cuttlefish/shared/device.mk`.\n\n $(call soong_config_append,cvd,launch_configs,cvd_config_\u003cvar translate=\"no\"\u003ebig_phone\u003c/var\u003e)\n\n 3. Create an `android_info.txt` file and tie the `big_phone` config to the\n file by adding the following line to\n `device/google/cuttlefish/vsoc_x86_64/`\u003cvar translate=\"no\"\u003ebig_phone\u003c/var\u003e`/aosp_cf.mk`:\n\n TARGET_BOARD_INFO_FILE := device/google/cuttlefish/vsoc_x86_64/\u003cvar\u003ebig_phone\u003c/var\u003e/android-info.txt\n\n 4. Label the device type with the `big_phone` config by populating\n `device/google/cuttlefish/vsoc_x86_64/`\u003cvar translate=\"no\"\u003ebig_phone\u003c/var\u003e`/android-info.txt`\n with the following:\n\n config=\u003cvar translate=\"no\"\u003ebig_phone\u003c/var\u003e"]]