我正在尝试从 AOSP 源代码创建一个 AVD 模拟器映像,我可以在我的 M1 Macbook (arm64) 上使用标准 Android 模拟器运行该映像。
我已遵循从 https://source.android.com/docs/setup/start/initializing 开始的所有标准步骤,其中包括:
sdk_phone_arm64
)https://source.android.com/docs/setup/create/avdm
make emu_img_zip
(在 Android 13 / 14 上)和 make sdk sdk_repo
(在 Android 11 / 12 上)创建模拟器图像,如此处所述 https://source.android.com/docs/setup/create/avd到目前为止,只有 Android 12 版本(来自此处的 android12-release 分支https://android.googlesource.com/platform/manifest/+refs)给了我一个实际启动且可用的模拟器。
android11-release
、android13-release
、android14-release
都生成了良好的构建,但模拟器从未启动并且似乎处于循环中,这里是来自 Android 13 构建的内核日志,这似乎是内核恐慌:
[ 0.359454][ T1] uart-pl011 9000000.pl011: no DMA platform data
[ 0.359992][ T1] VFS: Cannot open root device "(null)" or unknown-block(0,0): error -6
[ 0.360612][ T1] Please append a correct "root=" boot option; here are the available partitions:
[ 0.361315][ T1] 0100 8192 ram0
[ 0.361317][ T1] (driver?)
[ 0.361912][ T1] 0101 8192 ram1
[ 0.361913][ T1] (driver?)
[ 0.362513][ T1] 0102 8192 ram2
[ 0.362514][ T1] (driver?)
[ 0.363177][ T1] 0103 8192 ram3
[ 0.363178][ T1] (driver?)
[ 0.363761][ T1] 0104 8192 ram4
[ 0.363761][ T1] (driver?)
[ 0.364361][ T1] 0105 8192 ram5
[ 0.364361][ T1] (driver?)
[ 0.364976][ T1] 0106 8192 ram6
[ 0.364977][ T1] (driver?)
[ 0.365559][ T1] 0107 8192 ram7
[ 0.365560][ T1] (driver?)
[ 0.366179][ T1] 0108 8192 ram8
[ 0.366180][ T1] (driver?)
[ 0.366777][ T1] 0109 8192 ram9
[ 0.366777][ T1] (driver?)
[ 0.367363][ T1] 010a 8192 ram10
[ 0.367363][ T1] (driver?)
[ 0.367949][ T1] 010b 8192 ram11
[ 0.367949][ T1] (driver?)
[ 0.368532][ T1] 010c 8192 ram12
[ 0.368533][ T1] (driver?)
[ 0.369119][ T1] 010d 8192 ram13
[ 0.369119][ T1] (driver?)
[ 0.369730][ T1] 010e 8192 ram14
[ 0.369730][ T1] (driver?)
[ 0.370359][ T1] 010f 8192 ram15
[ 0.370360][ T1] (driver?)
[ 0.370951][ T1] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
[ 0.371710][ T1] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.15.41-android13-8-00029-g24d27dff64c4-ab9178016 #1
[ 0.359088][ T1] Hardware name: linux,ranchu (DT)
[ 0.359470][ T1] Call trace:
[ 0.359766][ T1] dump_backtrace.cfi_jt+0x0/0x8
[ 0.360137][ T1] dump_stack_lvl+0x80/0xb8
[ 0.360472][ T1] panic+0x180/0x444
[ 0.360764][ T1] mount_block_root+0x1ac/0x270
[ 0.361123][ T1] mount_root+0x68/0x90
[ 0.361454][ T1] prepare_namespace+0x164/0x1e8
[ 0.361825][ T1] kernel_init_freeable+0x120/0x19c
[ 0.362282][ T1] kernel_init+0x40/0x36c
[ 0.362606][ T1] ret_from_fork+0x10/0x20
[ 0.362938][ T1] SMP: stopping secondary CPUs
[ 0.363367][ T1] Kernel Offset: disabled
[ 0.363708][ T1] CPU features: 0x0,00000281,4b354ee8
[ 0.364112][ T1] Memory Limit: none
[ 0.000000][ T0] Booting Linux on physical CPU 0x0000000000 [0x00000000]
[ 0.000000][ T0] Linux version 5.15.41-android13-8-00029-g24d27dff64c4-ab9178016 (build-user@build-host) (Android (8508608, based on r450784e) clang version 14.0.7 (https://android.googlesource.com/toolchain/llvm-project 4c603efb0cca074e9238af8b4106c30add4418f6), LLD 14.0.7) #1 SMP PREEMPT Fri Oct 14 19:05:44 UTC 2022
[ 0.000000][ T0] Machine model: linux,ranchu
[ 0.000000][ T0] Stack Depot is disabled
[ 0.000000][ T0] KVM is not available. Ignoring kvm-arm.mode
[ 0.000000][ T0] printk: debug: skip boot console de-registration.
不确定这些模拟器日志从一开始是否相关,但可能会有帮助
❯ emulator @Test_Device2 -show-kernel
INFO | Android emulator version 33.1.13.0 (build_id 10332831) (CL:N/A)
INFO | Found systemPath /Users/username_here/Library/Android/sdk/system-images/android-33/default/arm64-v8a/
INFO | Storing crashdata in: , detection is enabled for process: 40462
INFO | Duplicate loglines will be removed, if you wish to see each individual line launch with the -log-nofilter flag.
INFO | Increasing RAM size to 2048MB
INFO | Warning: QMetaObject::connectSlotsByName: No matching signal for on_new_posture_requested(int) ((null):0, (null))
INFO | Warning: QMetaObject::connectSlotsByName: No matching signal for on_dismiss_posture_selection_dialog() ((null):0, (null))
INFO | Warning: QMetaObject::connectSlotsByName: No matching signal for on_new_resizable_requested(PresetEmulatorSizeType) ((null):0, (null))
INFO | Warning: QMetaObject::connectSlotsByName: No matching signal for on_dismiss_resizable_dialog() ((null):0, (null))
library_mode host gpu mode host
WARNING | cannot add library /Users/username_here/Library/Android/sdk/emulator/qemu/darwin-aarch64/lib64/vulkan/libvulkan.dylib: failed
INFO | added library /Users/username_here/Library/Android/sdk/emulator/lib64/vulkan/libvulkan.dylib
我不会更改 AOSP 源代码上的任何内容,并且所有构建都可以通过相同的步骤顺利成功。如何获得可用的 Android 13 / 14 模拟器映像?
通过 Android Studio 下载的 Stock arm64 模拟器图像工作正常。
我无法在我正在构建的机器上运行
emulator
命令,因为那是在不支持虚拟化的云 Linux 机器上。
这很有趣,因为目前我也遇到了完全相同的问题。
在我的构建中我可以找到该文件:
out/target/product/emulator_x86_64/sdk-repo-linux-system-images.zip
我想你可以找到类似的文件。该 zip 是 AVD 图像。
有一个官方指南(你已经知道了),但它仅适用于Android 12及以下版本。因为它说在 Android 12 及更低版本上您还可以在构建中找到
repo-sys-img.xml
。将 AVD 添加到 Android Studio 需要此文件。但较新的 Android 版本又如何呢?它什么也没说,而且我在我的 Android 15 版本中也找不到这样的文件。
需要的
repo-sys-img.xml
就像这个文件:https://dl.google.com/android/repository/sys-img/android/sys-img2-3.xml。
我从下面的屏幕截图中找到了这个链接。通常您可以构建此文件,但由于它不在构建中,我现在唯一的想法是从链接中获取此 XML 文件并对其进行编辑。
我昨天向 android-building Google 群组添加了一个问题,但尚未被接受。
这是必须添加 XML 文件的位置(我猜它必须以
file://...
开头):