记录使用ASFP + Cuttlefish 调试AOSP的踩坑历程
工欲善其事,必先利其器,入门先看这篇,心里有个大概流程,然后再去操作
💥 标记的提示,是必踩的坑
文末有省流版
编译AOSP
硬件要求
https://source.android.com/docs/setup/start
A minimum of 64 GB of RAM. Google uses 72-core machines with 64 GB of RAM to build Android. With this hardware configuration, it takes approximately 40 minutes for a full build of Android and only a few minutes for incremental build of Android. By contrast, it takes approximately 6 hours for a full build with a 6-core machine with 64 GB of RAM.
72核,64G内存机器完整编译需要40分钟;6核64G机器差不多6个小时。
不幸的是,我是9代i5,6核32G,需要7小时21分。
每个 Repo 检出分支都由一个清单文件表示。您可以同时拥有多个 Repo 检出分支,只要它们位于不同的目录中即可。但请注意,每个检出分支和 build 大约需要使用 300 GB 存储空间(并且会不断增加),因此请不要超过 2 个 Repo 检出分支,或者也可以使用附加硬盘为您的系统扩容。
我检出了master
和androi-15.0.0_r3
,磁盘使用空间如图:
综上:
编译AOSP,高IO,高CPU占用,对显卡无要求。
💥 重中之重:内存小的话,一定要加大swap,RAM + swap >= 64G
How to increase Swap Space in Ubuntu 24.04 or 22.04 LTS
操作系统:Ubuntu desktop x86_64
💥 当前时间节点【2024年12月6日】,选择22.04LTS而不是24.0.1LTS
- 虚拟机安装
- 不太推荐,优点是可以装在移动盘里随身携带
- win + wsl 安装
- 无缝体验,很方便
- 双系统【没测试】
- Ubuntu PC
- 我的选择
依赖包安装
💥 To install required packages for Ubuntu 18.04 or later, run the following command:
sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig
分支选择
repo init --partial-clone -b main -u https://android.googlesource.com/platform/manifest
这里默认是master分支,不要这样做。
💥 repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-15.0.0_r3
指定目标版本。
💥 清华镜像/华科镜像选其一,清华镜像更顺手。
选择固件
问题一:lunch之后,没有出现menu选项。
Warning: Cannot display lunch menu.
1、lunch
2、回车,选择到默认的
3、build_build_var_cache
4、再lunch,应该能显示所有选项了
💥 注意:固件选择-eng结尾的,不要选择userdebug结尾的。否则无法调试。
比如:aosp_cf_x86_64_phone-trunk_staging-eng
如果选择了非eng结尾的,处理办法:
$ adb root
$ adb shell setprop persist.debug.dalvik.vm.jdwp.enabled 1
$ adb reboot
源码参考:com.android.internal.os.Zygote.java
/**
* This will enable jdwp by default for all apps. It is OK to cache this property
* because we expect to reboot the system whenever this property changes
*/
private static final boolean ENABLE_JDWP = SystemProperties.get(
"persist.debug.dalvik.vm.jdwp.enabled").equals("1");
/**
* This will enable ptrace by default for all apps. It is OK to cache this property
* because we expect to reboot the system whenever this property changes
*/
private static final boolean ENABLE_PTRACE = SystemProperties.get(
"persist.debug.ptrace.enabled").equals("1");
/**
* Applies debugger system properties to the zygote arguments.
*
* For eng builds all apps are debuggable with JDWP and ptrace.
*
* On userdebug builds if persist.debug.dalvik.vm.jdwp.enabled
* is 1 all apps are debuggable with JDWP and ptrace. Otherwise, the
* debugger state is specified via the "--enable-jdwp" flag in the
* spawn request.
*
* On userdebug builds if persist.debug.ptrace.enabled is 1 all
* apps are debuggable with ptrace.
*
* @param args non-null; zygote spawner args
*/
static void applyDebuggerSystemProperty(ZygoteArguments args) {
if (Build.IS_ENG || (Build.IS_USERDEBUG && ENABLE_JDWP)) {
args.mRuntimeFlags |= Zygote.DEBUG_ENABLE_JDWP;
// Also enable ptrace when JDWP is enabled for consistency with
// before persist.debug.ptrace.enabled existed.
args.mRuntimeFlags |= Zygote.DEBUG_ENABLE_PTRACE;
}
if (Build.IS_ENG || (Build.IS_USERDEBUG && ENABLE_PTRACE)) {
args.mRuntimeFlags |= Zygote.DEBUG_ENABLE_PTRACE;
}
}
Cuttlefish
墨鱼是模拟器 ,支持本地和云端部署。
墨鱼包含在AOSP中。
如果,做兼容性测试的话,从Android 持续集成网站下载目标版本到本地,然后解压运行;
如果,自己编译AOSP,直接本地运行。
- /usr/lib/cuttlefish-common/bin下缺少文件
Launching CVD using --config='phone'.
sh: 1: /usr/lib/cuttlefish-common/bin/capability_query.py: not found
VM manager crosvm is not supported on this machine.
Invalid vm_manager: crosvm
05-18 17:19:04.235 33644 33644 E launch_cvd: subprocess.cpp:219 Subprocess 33665 was interrupted by a signal 'Aborted' (6)
05-18 17:19:04.235 33644 33644 E launch_cvd: [main.cc:461](http://main.cc:461/) assemble_cvd returned -1
把android-cuttlefish/base/host/deploy下的capability_query.py ,unpack_boot_image.py放到/usr/lib/cuttlefish-common/bin/下
$ubuntu-server:~$ ls /usr/lib/cuttlefish-common/bin/
capability_query.py unpack_boot_image.py
- 缺少cvdnetwork组
user@user:/F/cf$ sudo usermod -aG kvm,cvdnetwork,render $USER
[sudo] user 的密码:
usermod:“cvdnetwork”组不存在
user@user:/F/cf$ sudo addgroup cvdnetwork
正在添加组"cvdnetwork" (GID 1004)...
完成。
user@user:/F/cf$ sudo usermod -aG kvm,cvdnetwork,render $USER
更多问题,参考:启动Cuttlefish模拟器遇到的问题
💥 注意:更新显卡驱动
ASFP
💥 注意:只有Linux平台版本
约等于,Android Studio带插件。
💥 注意:如果sync失败,检查asfp-config.json
文件的 "lunchTarget" : "aosp_cf_x86_64_phone-trunk_staging-eng"
和编译前lunch的参数是否一致。
💥 注意:Android Studio Ladybug | 2024.2.1 Patch 2 版本,是没有Attatch to process
快捷图标的。使用Ctrl + Alt + A 呼出,或者双shift 全局搜索debug。如图:
省流版本
💥 系统使用Ubuntu 2204
💥 内存+swap必须大于64G
💥 使用1TSSD
💥 使用清华镜像
💥 repo init
不要使用master
,必须指定目标分支
💥 编译时,lunch
必须选择带eng
才能调试
💥 asfp
导入后,sync unsuccessful
,保证lunch target
字符串一致
💥 asfp
中找不到Attatch to process
快捷图标, double shift 全局搜索debug
关键字
💥 花点时间读官方文档