Cuttlefish

Cuttlefish (CVD) is a virtual Android device framework that allows you to run Android virtual devices on various hosts. It is widely used in the context of AOSP (Android Open Source Project) development, including in automotive contexts. The Cuttlefish setup includes a set of commands prefixed with cvd that manage these virtual devices.

Common Cuttlefish Commands

Here are some of the most common Cuttlefish commands:

  1. cvd start: This command is used to start a Cuttlefish virtual device instance. By default, it starts one instance of the Android virtual device.

    • Usage: cvd start

    • You can pass additional flags to customize the start process, such as specifying the instance number or other configurations.

  2. cvd stop: Stops a running Cuttlefish virtual device instance.

    • Usage: cvd stop

    • You can stop specific instances by providing the instance number, e.g., cvd stop --instance 2.

  3. cvd status: Displays the status of all running Cuttlefish instances.

    • Usage: cvd status

    • You can see whether the instance is running or stopped, along with additional details about each instance.

  4. cvd reset: This command resets the Cuttlefish instance, effectively reinitializing the device.

    • Usage: cvd reset

    • You can also reset specific instances with --instance flag.

  5. cvd kill: Kills the entire Cuttlefish process for a given instance.

    • Usage: cvd kill

  6. cvd stop-group: Stops all instances in a group.

    • Usage: cvd stop-group

  7. cvd logs: Fetches and displays logs for debugging purposes.

    • Usage: cvd logs --instance <id>

  8. cvd restart: Restarts the Cuttlefish instance.

    • Usage: cvd restart

  9. cvd help: Displays help information for the cvd command suite.

    • Usage: cvd help

Concepts of CVD Instance and CVD Groups

  • CVD Instance: A CVD instance represents a single virtual Android device running on your host. Each instance has its own dedicated resources and configuration. You can run multiple CVD instances simultaneously, each identified by an instance ID.

    When you start a Cuttlefish virtual device using the cvd start command, it creates a new instance. If you specify multiple instances, Cuttlefish will manage each separately.

    • Example: Running multiple instances can be done with cvd start --num_instances 2, which starts two instances.

  • CVD Group: A CVD group is a collection of CVD instances that are treated as a single entity for certain operations. This is useful when managing multiple instances collectively, such as stopping or starting them all at once.

    For example, using cvd stop-group would stop all instances in the group instead of managing them individually.

Managing Multiple CVD Instances

You can manage multiple CVD instances through a combination of instance-specific commands and flags. Here’s how you can handle multiple instances:

  1. Starting multiple instances: You can start multiple CVD instances by using the --num_instances flag with the cvd start command.

    • Example: cvd start --num_instances 3 would start three virtual Android devices.

  2. Controlling specific instances: Most CVD commands accept an --instance flag to target specific instances by their ID.

    • Example: cvd stop --instance 2 would stop instance 2.

  3. Viewing instance details: You can view the details of all running instances with the cvd status command. This will show you the instance IDs and their statuses.

    • Example: cvd status

  4. Stopping all instances: You can stop all running instances at once using cvd stop-group. This is useful when you have multiple instances running and want to shut them down in a single command.

    • Example: cvd stop-group

  5. Resetting specific instances: To reset a particular instance, you can use the cvd reset command with the instance ID.

    • Example: cvd reset --instance 3

  6. Fetching logs for specific instances: Use cvd logs --instance <id> to retrieve logs for individual instances. This is helpful for debugging issues with specific virtual devices.

Example Workflow with Multiple Instances

  1. Start three instances of CVD:

  2. Check the status of all instances:

  3. Stop the second instance:

  4. Reset the first instance:

  5. Stop all instances at once:

By using these commands and concepts, you can efficiently manage multiple virtual Android devices in your Cuttlefish setup, making it easier to work with AOSP environments, including for automotive development or general Android testing purposes.

Last updated