1# Android Emulator (goldfish)
2
3The built-in local emulator is the quickest way how to get started with KVM and Android.
4
5## x86_64
6
7KVM on x86_64 does not provide the same guest protection as arm64 but you will be able to spawn
8virtual machines and use the same APIs to communicate with the guest. The main reason for choosing
9the x86_64 emulator over its arm64 counterpart is performance. With native virtualization it is
10easily 10x faster than arm64 emulation.
11
12For optimal performance make sure to
13[enable nested virtualization](https://www.linux-kvm.org/page/Nested_Guests) on your machine.
14Don't forget to add your user account into the `kvm` group, then re-login for it to take effect.
15``` shell
16$ sudo gpasswd -a $USER kvm
17```
18
19Build Android for the emulator:
20``` shell
21$ . build/envsetup.sh
22$ lunch sdk_phone_x86_64-eng
23$ m -j$(nproc)
24```
25
26Once you have an Android image, invoke `emulator`. The script will automatically find the image you
27just built and run it in QEMU.
28``` shell
29$ emulator -no-window -show-kernel -writable-system -qemu -cpu host
30```
31Explanation of the arguments:
32  * `-no-window`: run headless
33  * `-show-kernel`: print kernel UART logs to the console (useful for debugging),
34  * `-writable-system`: support remounting `system/` as writable, needed for `adb sync`,
35  * `-qemu -cpu host`: needed to enable nested virtualization, instructs QEMU to allow Android
36    access CPU features of the host kernel
37
38If you get an error saying “x86_64 emulation currently requires hardware acceleration!”, your
39user account is not in the `kvm` group (see above).
40
41You should now see the virtual device when you run:
42``` shell
43$ adb devices
44List of devices attached
45emulator-5554   device
46```
47