❤️

使用 ASfP 阅读和调试 AOSP

使用 ASfP 阅读和调试 AOSP

背景在 MacBook Pro M3 Max 上编译 AOSP 的文章中提到了使用 OrbStack 进行 AOSP 项目编译,但是对于代码查看和调试不方便,用了 idea, vscode 的 remote 方式都有些问题,还是选用官方推荐的 Ubuntu 配合 ASfP 的方式更合适。

设备硬盘 2 TB,源码加编译产物使用了差不多 900GB 多

CPU

Intel® Core™ i5 processor 14600KF 24M Cache

GPU

INNO3D GEFORCE RTX 4070 SUPER 曜夜OC

RAM

芝奇 幻锋戟 32GB * 2 DDR5 6400

HDD

致态 TiPlus 7100 2TB NVMe M.2 PCIe4.0

编译配置针对 Pixel 6 编译,考虑到节省磁盘空间,移除了部分非必要项目。

在 .repo 目录下新增 local_manifests 目录,添加需要移除的项目的配置。后续 repo sync 就不会同步对应移除项目的代码。

123$ mkdir -p .repo/local_manifests/$ touch .repo/local_manifests/device_clean.xml$ touch .repo/local_manifests/jdk_clean.xml

移除非 oriole(Pixel 6) 未使用到的其他 device 项目

device_clean.xml

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869

移除部分 jdk

jdk_clean.xml

12345

耗时其中 -j 指定了 12,其他任务并行执行电脑也不感觉到卡顿。耗时 1小时 10 分钟完成。

1$ make otapackage -j12 WITH_DEXPREOPT=false

123452024-05-01 10:26:01 - common.py - INFO : Running: "java -Xmx4096m -Djava.library.path=out/host/linux-x86/lib64 -jar out/host/linux-x86/framework/signapk.jar -w build/make/target/product/security/testkey.x509.pem build/make/target/product/security/testkey.pk8 /home/shumxin/AOSP/14.0.0_r29/out/soong/.temp/tmpsmayeaza.zip out/target/product/oriole/aosp_oriole-ota.zip"2024-05-01 10:26:03 - ota_from_target_files.py - INFO : done.#### build completed successfully (01:10:17 (hh:mm:ss)) ####

调试导入 ASfP

在 android 14 上如果编译的固件类型是 userdebug,发现无法 attach process 进行 debug。

官方 commit 如下

123456789101112131415161718192021222324252627282930313233diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.javaindex b1e7d15..deafd19 100644--- a/core/java/com/android/internal/os/Zygote.java+++ b/core/java/com/android/internal/os/Zygote.java@@ -1001,16 +1001,24 @@ } /**+ * 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");++ /** * Applies debugger system properties to the zygote arguments. *- * If "ro.debuggable" is "1", all apps are debuggable. Otherwise,- * the debugger state is specified via the "--enable-jdwp" flag- * in the spawn request.+ * For eng builds all apps are debuggable. On userdebug and user builds+ * if persist.debuggable.dalvik.vm.jdwp.enabled is 1 all apps are+ * debuggable. Otherwise, the debugger state is specified via the+ * "--enable-jdwp" flag in the spawn request. * * @param args non-null; zygote spawner args */ static void applyDebuggerSystemProperty(ZygoteArguments args) {- if (RoSystemProperties.DEBUGGABLE) {+ if (Build.IS_ENG || ENABLE_JDWP) { args.mRuntimeFlags |= Zygote.DEBUG_ENABLE_JDWP; } }

通过如下配置可开启 debug 进行应用调试

123$ adb root$ adb shell setprop persist.debug.dalvik.vm.jdwp.enabled 1$ adb reboot

参考

[1] Android Studio for Platform

[2] Android Local Manifests机制的使用实践

[3] 使用 ASfP 搭建 Android Framwork 开发调试阅读环境

许可协议

本文采用 署名-非商业性使用-相同方式共享 4.0 国际 许可协议,转载请注明出处。

🎀 相关推荐

VB.NET连接SQL数据库
365提款会被冻结卡吗

VB.NET连接SQL数据库

📅 06-30 👀 9566
军团战争隐藏兵种有哪些?军团战争隐藏兵种介绍
甜心选择2 Honey Select 2 最新完整汉化版 PC端定制指南