0 前言
为模拟器编译镜像和为真机编译有所不同,本文梳理Android-P为模拟器编译源码的方法。
1 aosp
1.1 aosp_arm-eng
根据参考资料[1]的方式,编译源码之后,直接执行emulator即可启动模拟器,但会提示:

根据提示,x86的版本会更加快!
启动过程一直卡在开机动画位置,有待解决。
1.2 aosp_arm64-eng
1.2.1 错误
运行emulator64-arm遇到一些错误:
(1)错误1

解决方法:
sudo apt-get install libqt5widgets5
(2)错误2

2 sdk
直接"lunch aosp_x86_64-eng"所编译出来的镜像容易出现各种闪退现象(例如系统设置界面)。通过Android Studio的设备管理器提下载的官方镜像发现是sdk版本,再结合参考资料[8]的提示,可lunch下面选项之一进行编译。
lunch sdk_x86_64-eng
sdk_phone_x86_64-eng
lunch sdk_x86_64-userdebug
sdk_phone_x86_64-userdebug
3 lunch
android-9.0.0_r10源码“lunch menu”输出如下:
You're building on Linux
Lunch menu... pick a combo:
1. aosp_arm-eng # @build/make/envsetup.sh
2. aosp_arm64-eng # 同上
3. aosp_mips-eng # 同上
4. aosp_mips64-eng # 同上
5. aosp_x86-eng # 同上
6. aosp_x86_64-eng # 同上
7. aosp_car_arm-userdebug # @device/generic/car/vendorsetup.sh
8. aosp_car_arm64-userdebug # 同上
9. aosp_car_x86-userdebug # 同上
10. aosp_car_x86_64-userdebug # 同上
11. mini_emulator_arm64-userdebug # @device/generic/mini-emulator-arm64/vendorsetup.sh
12. m_e_arm-userdebug # @device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
13. m_e_mips64-eng # @device/generic/mini-emulator-mips64/vendorsetup.sh
14. m_e_mips-userdebug # @device/generic/mini-emulator-mips/vendorsetup.sh
15. mini_emulator_x86_64-userdebug # @device/generic/mini-emulator-x86_64/vendorsetup.sh
16. mini_emulator_x86-userdebug # @device/generic/mini-emulator-x86/vendorsetup.sh
17. uml-userdebug # @device/generic/uml/vendorsetup.sh
18. aosp_cf_x86_auto-userdebug # @device/google/cuttlefish/vendorsetup.sh
19. aosp_cf_x86_phone-userdebug # 同上
20. aosp_cf_x86_tablet-userdebug # 同上
21. aosp_cf_x86_tablet_3g-userdebug # 同上
22. aosp_cf_x86_tv-userdebug # 同上
23. aosp_cf_x86_wear-userdebug # 同上
24. aosp_cf_x86_64_auto-userdebug # 同上
25. aosp_cf_x86_64_phone-userdebug # 同上
26. aosp_cf_x86_64_tablet-userdebug # 同上
27. aosp_cf_x86_64_tablet_3g-userdebug # 同上
28. aosp_cf_x86_64_tv-userdebug # 同上
29. aosp_cf_x86_64_wear-userdebug # 同上
30. cf_x86_auto-userdebug # 同上
31. cf_x86_phone-userdebug # 同上
32. cf_x86_tablet-userdebug # 同上
33. cf_x86_tablet_3g-userdebug # 同上
34. cf_x86_tv-userdebug # 同上
35. cf_x86_wear-userdebug # 同上
36. cf_x86_64_auto-userdebug # 同上
37. cf_x86_64_phone-userdebug # 同上
38. cf_x86_64_tablet-userdebug # 同上
39. cf_x86_64_tablet_3g-userdebug # 同上
40. cf_x86_64_tv-userdebug # 同上
41. cf_x86_64_wear-userdebug # 同上
42. aosp_marlin-userdebug # @device/google/marlin/vendorsetup.sh
43. aosp_marlin_svelte-userdebug # 同上
44. aosp_sailfish-userdebug # 同上
45. aosp_walleye-userdebug # @device/google/muskie/vendorsetup.sh
46. aosp_walleye_test-userdebug # 同上
47. aosp_taimen-userdebug # @device/google/taimen/vendorsetup.sh
48. hikey-userdebug # @device/linaro/hikey/vendorsetup.sh
49. hikey64_only-userdebug # 同上
50. hikey960-userdebug # 同上
参考“aosp_arm-eng”的实现,添加“sdk_xxx”选项到"lunch menu"的结果中:
# add the default one here
add_lunch_combo aosp_arm-eng
add_lunch_combo aosp_arm64-eng
add_lunch_combo aosp_mips-eng
add_lunch_combo aosp_mips64-eng
add_lunch_combo aosp_x86-eng
add_lunch_combo aosp_x86_64-eng
add_lunch_combo sdk_x86_64-eng # Added by OneSea
add_lunch_combo sdk_phone_x86_64-eng # Added by OneSea
add_lunch_combo sdk_x86_64-userdebug # Added by OneSea
add_lunch_combo sdk_phone_x86_64-userdebug # Added by OneSea
# @file: build/make/envsetup.sh
其中"sdk_phone_x86_64"定义如下:
$(call inherit-product, $(SRC_TARGET_DIR)/product/aosp_x86_64.mk)
# Define the host tools and libs that are parts of the SDK.
-include sdk/build/product_sdk.mk
-include development/build/product_sdk.mk
# Overrides
PRODUCT_BRAND := Android
PRODUCT_NAME := sdk_phone_x86_64
PRODUCT_DEVICE := generic_x86_64
PRODUCT_MODEL := Android SDK built for x86_64
# @file: build/make/target/product/sdk_phone_x86_64.mk
参考资料
[3]Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题
[4]解决qt.qpa.plugin: Could not find the Qt platform plugin “xcb“ in ““
[5]使用 Cuttlefish 虚拟 Android 设备
[7]Cuttlefish virtual android device deployment
[8]Android-S模拟器