Recently, I upgraded my local Android source code to the latest Android 15, and Android Studio for Platform, which is used to look at Android source code, has also been upgraded to the latest version. Google’s Cuttlefish has recently released version 1.0, and I’ve also tossed around the idea of using Cuttlefish to run I’ve been using Cuttlefish to run my own compiled Android, so here’s how to use it and the problems I’ve encountered.
What’s a Cuttlefish?
Cuttlefish is a virtual Android device from Google that can be configured to run on our local devices or on top of a server, and officially provides support for running on Docker, which can theoretically run on a Debian device locally or on a server, or on the Google Compute Engine! Docker can theoretically run on local or server Debian devices, or on Google Compute Engine.
In terms of officialization, it is an Android emulator that is closer to a real device, except for the Hardware Abstraction Layer (HAL), it is basically the same functional performance as a physical device. Using it for CTS testing, continuous integration testing will have higher fidelity.
Running it in the command line, there is no emulator-like UI, we can see its UI in two ways, one is through ADB connection, and the other is to turn on its webrtc function to view and interact with it in the browser. And his virtual hardware feature allows us to simulate multiple screens, test bluetooth wifi and various other features.
Installing Cuttlefish and compiling Android firmware
First we need to check if our device supports KVM virtualization using the following command:
|
|
If you get a non-zero value, it is supported.
After that we need to have an Android firmware that can optionally go to theAndroid Continuous Integration WebsiteDownload their compiled firmware, you can also compile your own firmware. Download the firmware should pay attention to download the device target with cf, and download the target CPU and need to run the host CPU architecture, ARM on the download of ARM, X86 on the download of X86_64, the specific operation can see the official tutorial. I here is their own compilation, using the following code device I want to compile the options:
|
|
That way with the firmware, it still won’t be able to run. We still need to go and compile Cuttlefish in thehttps://github.com/google/android-cuttlefishAfter downloading the source code, execute the following code in the cuttlefish source directory to compile and Android:
|
|
If you’re lucky with the chemistry, the above will work all at once, but I’m not a lucky guy. So got an error similar to the following:
|
|
The reason for this error is that the build tool bazel is used when compiling cuttlefish, which relies on the JDK, and I didn’t set theJAVA_HOME
This environment variable, so just add it to the environment variable. Something like the following:
export JAVA_HOME=/usr/lib/jvm/zulu-17-amd64
After the setup is complete, check in the Cuttlefish project directory with the following command to see if the JAVA_HOME is set correctly:
|
|
But after messing with it, I had another problem when installing the two deb files, telling me that my computer’sgrub-common
There is an error in the signature, this is because I added the Copper Pea repository before, and when I upgraded grub, I upgraded the grub package of Copper Pea, which is different from the official one of ubuntu, so I uninstalled the Copper Pea repository, and grub-common was reinstalled, and after that, I had no problem. After all this, we run the following commands to set up the environment and reboot the computer.
|
|
使用Cuttlefish
In our compiled Android system directory, first execute the following code to initialize the environment:
|
|
The following command will then launch Cuttlefish to run Android:
|
|
If you are downloading from the official Android, then there will be some differences with me, so check out the official tutorial.
At this time we can use adb to see if the device has been booted, or you can open it in a browser and browse locally for its opening using the following address and port:
https://localhost:8443/
Be sure to use https for the address and click the swtich button on the left to see the UI. webrtc is turned on by default, for more usage of its command line you can check the official documentation, which can be viewed using the following command.
|
|
And shutting down Cuttlefish is as simple as using the following command:
|
|
新版Android Studio for Platform使用
Version 2023 of Android Studio for Platform (hereafter referred to as Asfp) opens with a separateOpen Aosp project
The new version removes this option. I was confused when I first used it and tested Import and Open, but finally realized that the new version of theNew
The option is directly an import of the Aosp project.
The way to use it is shown below.
We can choose the Module we need to import according to the above figure, choose the location where the project file generated by Asfp for us is stored, after which Asfp will execute thelunch
operation and some of the dependency builds it requires. Underneath our selected directory will also generate aasfp-config.json
file, it is our project settings, if we have changes in the future (such as want to see the code of different modules), we can also directly modify this file.
|
|
Reference content and information:
- Cuttlefish Official Documentation:https://source.android.com/docs/devices/cuttlefish
- Cuttlefish Official Repo:https://github.com/google/android-cuttlefish
- Bazel User’s Guide:https://bazel.build/docs/user-manual
- Android Cuttlefish emulator:https://2net.co.uk/blog/cuttlefish-android12.html