You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从源码编译Android Emulator及相关组件?

Android Emulator (AOSP main Branch) Full Build & Custom Logging Guide

Prerequisites (Debian)

Install required dependencies for AOSP and emulator compilation:

sudo apt update && sudo apt install -y openjdk-17-jdk git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig

Sync Complete AOSP Codebase

Initialize and sync the main branch, which includes all emulator-related repositories:

repo init -u https://android.googlesource.com/platform/manifest -b main
repo sync -j$(nproc)

Key paths for emulator components:

  • Emulator core: external/qemu/
  • Device-side client components (OpenGL forwarding, HAL services): frameworks/native/opengl/, hardware/google/emulator/

Component 1: Build Custom Goldfish Kernel

  1. Navigate to the Goldfish kernel directory:
cd kernel/goldfish
  1. Configure the kernel for x86_64 emulator:
ARCH=x86_64 make goldfish_x86_64_defconfig
  1. Modify kernel code to add custom logs (e.g., add printk statements in driver files), then compile:
ARCH=x86_64 make -j$(nproc)
  1. The compiled kernel image is at arch/x86_64/boot/bzImage; specify it with the -kernel flag when launching the emulator.

Component 2 & 3: Build Device-side Images with Custom Logs

These components are part of the Android system image. Use the following steps:

  1. Return to the AOSP root, select the correct build target (replaces the outdated sdk_phone_x86_64-userdebug):
lunch aosp_x86_64-userdebug

For ARM64 emulators, use aosp_arm64-userdebug instead.

  1. Add custom logs to device-side code:
    • OpenGL forwarding: Edit files under frameworks/native/opengl/libs/EGL/ or frameworks/native/opengl/libs/GLESv2/, add ALOGD/ALOGV statements
    • Modem HAL services: Edit code in hardware/google/emulator/modem/ to add logs
  2. Compile system images:
make -j$(nproc) systemimg vendorimg ramdiskimg

Compiled images are stored in out/target/product/generic_x86_64/.

Component 4: Build Custom Emulator Binary

Replace the prebuilt emulator binary with your own build:

  1. From AOSP root, compile the emulator:
make emulator -j$(nproc)
  1. Add custom logs to emulator code: Edit files in external/qemu/ (e.g., client request handling, rendering, input forwarding logic), then re-run make emulator
  2. The compiled binary is located at out/host/linux-x86_64/bin/emulator

Launch Custom Emulator

Combine all components with this example command:

cd out/host/linux-x86_64/bin
./emulator -avd test_avd -kernel ../../../../kernel/goldfish/arch/x86_64/boot/bzImage -system ../../../../out/target/product/generic_x86_64/system.img -vendor ../../../../out/target/product/generic_x86_64/vendor.img -ramdisk ../../../../out/target/product/generic_x86_64/ramdisk.img -verbose

Use -verbose to enable detailed logging for debugging your custom log statements.

Troubleshooting

  • Missing emulator-compatible lunch targets: Ensure you synced the full main branch (partial syncs may omit required configs)
  • Emulator build dependency errors: Verify all Debian prerequisites are installed, especially OpenGL-related libraries

内容的提问来源于stack exchange,提问作者Kyoungwon Kim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 04:10:34