Launch an AOSP build in a Cuttlefish virtual device

system info

1. Launch an AOSP build in a Cuttlefish virtual device

1.1 In a terminal window, download, build, and install the host Debian packages:

sudo apt install -y git devscripts equivs config-package-dev debhelper-compat golang curl
git clone https://github.com/google/android-cuttlefish
cd android-cuttlefish
tools/buildutils/build_packages.sh
sudo dpkg -i ./cuttlefish-base_*_*64.deb || sudo apt-get install -f
sudo dpkg -i ./cuttlefish-user_*_*64.deb || sudo apt-get install -f
sudo usermod -aG kvm,cvdnetwork,render $USER
sudo reboot

1.1.1 When building android-cuttlefish on Ubuntu 24.04, I encountered a make error

make[1]: Entering directory ‘/home/jmagic/androidpi/android-cuttlefish/base’

cd cvd && bazel build –linkopt=”-Wl,–build-id=sha1″ ‘cuttlefish/package:cvd’ –spawn_strategy=local –workspace_status_command=../stamp_helper.sh –build_tag_filters=-clang-tidy

Computing main repo mapping:

Loading:

Loading: 0 packages loaded

Analyzing: target //cuttlefish/package:cvd (0 packages loaded, 0 targets configured)

Analyzing: target //cuttlefish/package:cvd (0 packages loaded, 0 targets configured)

INFO: Analyzed target //cuttlefish/package:cvd (0 packages loaded, 0 targets configured).

ERROR: /home/jmagic/.cache/bazel/_bazel_jmagic/c47e5a21b28a6205c6fd9a8a2bf956de/external/zlib+/BUILD.

bazel:78:11: Compiling infback.c failed: (Exit 127): cc_wrapper.sh failed: error executing CppCompile command (from target @@zlib+//:z) external/toolchains_llvm++llvm+llvm_toolchain/bin/cc_wrapper.sh -U_FORTIFY_SOURCE ‘–target=x86_64-unknown-linux-gnu’ -U_FORTIFY_SOURCE -fstack-protector -fno-omit-frame-pointer -fcolor-diagnostics … (remaining 30 arguments skipped)

external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/clang: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

Target //cuttlefish/package:cvd failed to build

Use –verbose_failures to see the command lines of failed build steps.

INFO: Elapsed time: 0.236s, Critical Path: 0.02s

INFO: 38 processes: 1 action cache hit, 38 internal.

ERROR: Build did NOT complete successfully

make[1]: *** [debian/rules:25: override_dh_auto_build] Error 1

make[1]: Leaving directory ‘/home/jmagic/androidpi/android-cuttlefish/base’

make: *** [debian/rules:17: build] Error 2

dpkg-buildpackage: error: debian/rules build subprocess returned exit status 2

debuild: fatal error at line 1184:

dpkg-buildpackage -us -uc -ui -i -b failed

Check the dependencies of Clang:

ldd external/toolchains_llvm++llvm+llvm_toolchain_llvm/bin/clang
	linux-vdso.so.1 (0x000074d44715b000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x000074d44713f000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x000074d44713a000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x000074d447135000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x000074d43d317000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x000074d447119000)
	libtinfo.so.5 => not found
	libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x000074d43d000000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x000074d4470e9000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x000074d43cc00000)
	/lib64/ld-linux-x86-64.so.2 (0x000074d44715d000)

~/.cache/bazel/_bazel_jmagic/c47e5a21b28a6205c6fd9a8a2bf956de/external/toolchains_llvm+/toolchain/internal$

llvm_distributions.bzl

    # 17.0.6
    "clang+llvm-17.0.6-aarch64-linux-gnu.tar.xz": "6dd62762285326f223f40b8e4f2864b5c372de3f7de0731cb7cd55ca5287b75a",
    "clang+llvm-17.0.6-amd64-pc-solaris2.11.tar.xz": "8feb660750a4d24b18d8e894fbccf26bd0dfbc92581d202ec9057f00f3fbf232",
    "clang+llvm-17.0.6-arm64-apple-darwin22.0.tar.xz": "1264eb3c2a4a6d5e9354c3e5dc5cb6c6481e678f6456f36d2e0e566e9400fcad",
    "clang+llvm-17.0.6-powerpc64-ibm-aix-7.2.tar.xz": "3aeda4bb5808db2e47bde60cc49b15b869114e3681092413f7b297345d2e13ce",
    "clang+llvm-17.0.6-powerpc64le-linux-rhel-8.8.tar.xz": "04e18072797920c2b5e9bdf0c3ee9e5a61adf76bd5ffeb438fafd9e32fc48b62",
    "clang+llvm-17.0.6-sparcv9-sun-solaris2.11.tar.xz": "b7df7b383679af98640640f88114f461f38a6efdfe7c369692b0675751ac2773",
    "clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04.tar.xz": "884ee67d647d77e58740c1e645649e29ae9e8a6fe87c1376be0f3a30f3cc9ab3",

fix solution:

Update the llvm_version in the android-cuttlefish/base/cvd/MODULE.bazel file from 18.1.8 to 17.0.6 while keeping the rest of the configuration unchanged.

# android-cuttlefish/base/cvd/MODULE.bazel
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm.toolchain(
   # llvm_version = "18.1.8",
   llvm_version = "17.0.6",
)

1.2 Download aosp_cf_x86_64_phone-img-13283805.zip and cvd-host_package.tar.gz

https://ci.android.com/builds/submitted/13283805/aosp_cf_x86_64_phone-userdebug/latest

1.3 Launch Cuttlefish  

HOME=$PWD ./bin/launch_cvd --daemon

1.4 Verify that Cuttlefish is visible through adb

./bin/adb devices

1.5 Stop Cuttlefish

HOME=$PWD ./bin/stop_cvd

2. Launch an AOSP build using the Cuttlefish Docker image

https://github.com/google/android-cuttlefish/blob/main/docker/README.md

2.1 Download docker image

DOWNLOAD_LOCATION=us # Choose one among us, europe, or asia.
docker pull $DOWNLOAD_LOCATION-docker.pkg.dev/android-cuttlefish-artifacts/cuttlefish-orchestration/cuttlefish-orchestration

2.2 Start a Cuttlefish container using docker run and run an Android system instance inside the container

docker run -p 8443:8443 --privileged -itd -v /home/jmagic/androidpi/cuttlefish-instances/cuttlefish-aosp_cf_x86_64_phone:/cuttlefish-aosp_cf_x86_64_phone -w /cuttlefish-aosp_cf_x86_64_phone cuttlefish-orchestration:latest
Explanation of Each Component:
  • docker run:
    • This is the main command used to create and start a new container from an image.
  • -p 8443:8443:
    • The -p option maps a port on the host machine to a port inside the container.
    • In this case, port 8443 on the host is mapped to port 8443 inside the container. This allows network traffic on the host’s port 8443 to be forwarded to the container’s port 8443.
  • --privileged:
    • The --privileged flag gives the container elevated privileges, allowing it to access all devices on the host system and perform operations that are typically restricted.
    • This is often used for containers that need to perform low-level system tasks or interact with hardware.
  • -itd:
    • -i: Keeps the container’s standard input (stdin) open, enabling interaction with the container.
    • -t: Allocates a pseudo-TTY (terminal) for the container, which is useful for interactive sessions.
    • -d: Runs the container in “detached” mode, meaning it runs in the background without attaching to the terminal.
  • -v /home/jmagic/androidpi/cuttlefish-instances/cuttlefish-aosp_cf_x86_64_phone:/cuttlefish-aosp_cf_x86_64_phone:
    • The -v option mounts a directory or file from the host into the container.
    • Here, the directory /home/jmagic/androidpi/cuttlefish-instances/cuttlefish-aosp_cf_x86_64_phone on the host is mounted to /cuttlefish-aosp_cf_x86_64_phone inside the container.
    • This allows the container to access and modify files in the specified host directory.
  • -w /cuttlefish-aosp_cf_x86_64_phone:
    • The -w option sets the working directory inside the container.
    • In this case, the working directory is set to /cuttlefish-aosp_cf_x86_64_phone. Any commands executed inside the container will start from this directory by default.
  • cuttlefish-orchestration:latest:
    • This specifies the Docker image to use for creating the container.
    • The image name is cuttlefish-orchestration, and the tag is latest, which refers to the most recent version of the image.
docker exec -it 99ab bash
Explanation of Each Component:
  • docker exec:
    • The docker exec command is used to run a new command inside a running container.
    • It allows you to interact with or execute processes in a container that is already up and running.
  • -i:
    • The -i (interactive) flag keeps the container’s standard input (stdin) open.
    • This ensures that you can interact with the process running inside the container, such as typing commands into a shell.
  • -t:
    • The -t flag allocates a pseudo-TTY (terminal) for the container.
    • This creates an interactive terminal session, making it easier to interact with processes like a shell.
  • 99ab:
    • This is the ID or name of the container where the command will be executed.
    • In this case, 99ab is likely a shortened version of the container’s ID (the first few characters). Docker allows you to use either the full ID or a unique prefix of the ID to refer to a container.
  • bash:
    • This is the command being executed inside the container.
    • In this case, it starts a Bash shell (/bin/bash) inside the container, allowing you to interact with the container’s filesystem and processes through the terminal.

2.2.1 Launch cvd

2.2.2 cloud android device

2.2.3 Check devices using adb

2.2.4 Stop cvd

2.3 Stop and remove the Docker container

https://source.android.com/docs/devices/cuttlefish/get-started

https://ci.android.com

https://github.com/google/android-cuttlefish/blob/main/README.md