Android AOSP源码编译——AOSP整编(二)

切换到源码目录下执行下面命令

1、初始化环境

bash 复制代码
. build/envsetup.sh
//清除缓存
make clobber

2、选择编译目标

bash 复制代码
lunch

AOSP 预制了很多 Product。这里为了简单我们先不用真机,而是选择模拟器的方式,对于 x86_64 模拟器,我们选择的是 aosp_x86_64-eng。

lunch命令回车后会让你选择编译目标,我们选31(aosp_x86_64-eng)

bash 复制代码
maoweiyi@maoweiyi-OMEN-by-HP-Laptop-15-dc0xxx:~/aosp$ lunch

You're building on Linux

Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_arm64-eng
     3. aosp_barbet-userdebug
     4. aosp_blueline-userdebug
     5. aosp_blueline_car-userdebug
     6. aosp_bonito-userdebug
     7. aosp_bonito_car-userdebug
     8. aosp_bramble-userdebug
     9. aosp_car_arm-userdebug
     10. aosp_car_arm64-userdebug
     11. aosp_car_x86-userdebug
     12. aosp_car_x86_64-userdebug
     13. aosp_cf_arm64_auto-userdebug
     14. aosp_cf_arm64_phone-userdebug
     15. aosp_cf_x86_64_phone-userdebug
     16. aosp_cf_x86_auto-userdebug
     17. aosp_cf_x86_phone-userdebug
     18. aosp_cf_x86_tv-userdebug
     19. aosp_coral-userdebug
     20. aosp_coral_car-userdebug
     21. aosp_crosshatch-userdebug
     22. aosp_crosshatch_car-userdebug
     23. aosp_flame-userdebug
     24. aosp_flame_car-userdebug
     25. aosp_redfin-userdebug
     26. aosp_sargo-userdebug
     27. aosp_sunfish-userdebug
     28. aosp_trout_arm64-userdebug
     29. aosp_trout_x86-userdebug
     30. aosp_x86-eng
     31. aosp_x86_64-eng
     32. arm_krait-eng
     33. arm_v7_v8-eng
     34. armv8-eng
     35. armv8_kryo385-eng
     36. beagle_x15-userdebug
     37. beagle_x15_auto-userdebug
     38. car_x86_64-userdebug
     39. db845c-userdebug
     40. fuchsia_arm64-eng
     41. fuchsia_x86_64-eng
     42. hikey-userdebug
     43. hikey64_only-userdebug
     44. hikey960-userdebug
     45. hikey960_tv-userdebug
     46. hikey_tv-userdebug
     47. pixel3_mainline-userdebug
     48. poplar-eng
     49. poplar-user
     50. poplar-userdebug
     51. qemu_trusty_arm64-userdebug
     52. silvermont-eng
     53. uml-userdebug
     54. yukawa-userdebug
     55. yukawa_sei510-userdebug

Which would you like? [aosp_arm-eng] 31

3、编译

选择好编译目标,通过下面命令进行编译

bash 复制代码
//通过-jN 参数来设置编译的并行任务数,提高编译速度
make -j4

2000 years later~

看到build completed successfully就代表我们构建成功了。

接下来运行模拟器

运行模拟器

bash 复制代码
emulator

因为我们是刚编译, 执行过envsetup脚本和lunch,否则需要先执行这两条命令

bash 复制代码
. build/envsetup.sh
lunch 31
emulator

备注:在启动模拟器的时候遇到了磁盘空间不足,我看了下整个AOSP文件夹占用了我200多G,其中隐藏文件.repo占用了50G,考虑了下因为是学习后期不使用repo

sync同步更新代码,所以就给删除了。

到这里我们的模拟器就成功运行起来了

4、修改代码运行

最后我们尝试下修改我们的Activity.java,重新编译看看有没有生效。可以通过find -name "Activity.java"命令找到我们的Activity.java

找到后给Activity.java的onCreate加一行日志打印。
修改后保存,重新编译

bash 复制代码
. build/envsetup.sh
lunch 31
make -j4

编译成功再次运行模拟器

bash 复制代码
. build/envsetup.sh
lunch 31
emulator

打开终端 通过adb shelllogcat 命令查看日志
adb shell 的配置可自行百度。

点击模拟器中几个app后日志结果日下
可以看到我们修改的代码确实生效了。

相关推荐
lpruoyu2 小时前
【Android第一行代码学习笔记】Android架构_四大组件_权限_持久化_通知_异步_服务
android·笔记·学习
独自破碎E3 小时前
【BISHI15】小红的夹吃棋
android·java·开发语言
李堇6 小时前
android滚动列表VerticalRollingTextView
android·java
lxysbly8 小时前
n64模拟器安卓版带金手指2026
android
游戏开发爱好者811 小时前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
王码码203511 小时前
Flutter for OpenHarmony 实战之基础组件:第三十一篇 Chip 系列组件 — 灵活的标签化交互
android·flutter·交互·harmonyos
黑码哥11 小时前
ViewHolder设计模式深度剖析:iOS开发者掌握Android列表性能优化的实战指南
android·ios·性能优化·跨平台开发·viewholder
亓才孓11 小时前
[JDBC]元数据
android
独行soc11 小时前
2026年渗透测试面试题总结-17(题目+回答)
android·网络·安全·web安全·渗透测试·安全狮
金融RPA机器人丨实在智能11 小时前
Android Studio开发App项目进入AI深水区:实在智能Agent引领无代码交互革命
android·人工智能·ai·android studio