The emulator is good tool to test and prototype your product, and this article will show how to build it locally from your AOSP source code for your x86 architecture develop machine.

The building commands are very simple, and we can use following commands to build emulator:

source build/envsetup.sh
lunch sdk_phone_x86_64-userdebug
m
emulator

I have tested with target aosp_arm64, but the emulator will crash when running Android frequently, so I change target to aosp_x86_64, and emulator works fine in my work machine with architecture x86_64.

If you want to show the debug information of emulator, you can use the command emulator -verbose to start the emualtor. It will show many useful information to customize emualtor such as the path of emulator config(device/generic/goldfish/data/etc/config.ini).

Tips:

Please don’t build eng variant for emulator, it will cause Developer Optioins crash, because of the lack of oem_lock service.