前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >AOSP 源码整编单编

AOSP 源码整编单编

作者头像
吴小龙同學
发布2019-12-11 15:47:26
2.2K0
发布2019-12-11 15:47:26
举报
文章被收录于专栏:吴小龙同學吴小龙同學

AOSP 源码下载》完成后,就可以开编了。

整编

整编,顾名思义就是编译整个 Android 源码,最终 out 目录会生成几个重要的镜像文件,其中有 system.img、userdata.img、ramdisk.img 等,这些是可以刷机的。

初始化编译环境

项目目录,打开终端,输入命令:

代码语言:javascript
复制
source build/envsetup.sh

选择编译目标

命令:

代码语言:javascript
复制
lunch

输出:

代码语言:javascript
复制
You're building on Linux
Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_arm64-eng
     3. aosp_blueline-userdebug
     4. aosp_car_arm-userdebug
     5. aosp_car_arm64-userdebug
     6. aosp_car_x86-userdebug
     7. aosp_car_x86_64-userdebug
     8. aosp_cf_x86_64_auto-userdebug
     9. aosp_cf_x86_64_phone-userdebug
     10. aosp_cf_x86_64_tablet-userdebug
     11. aosp_cf_x86_64_tablet_3g-userdebug
     12. aosp_cf_x86_64_tv-userdebug
     13. aosp_cf_x86_64_wear-userdebug
     14. aosp_cf_x86_auto-userdebug
     15. aosp_cf_x86_phone-userdebug
     16. aosp_cf_x86_tablet-userdebug
     17. aosp_cf_x86_tablet_3g-userdebug
     18. aosp_cf_x86_tv-userdebug
     19. aosp_cf_x86_wear-userdebug
     20. aosp_crosshatch-userdebug
     21. aosp_marlin-userdebug
     22. aosp_sailfish-userdebug
     23. aosp_taimen-userdebug
     24. aosp_walleye-userdebug
     25. aosp_walleye_test-userdebug
     26. aosp_x86-eng
     27. aosp_x86_64-eng
     28. beagle_x15-userdebug
     29. hikey-userdebug
     30. hikey64_only-userdebug
     31. hikey960-userdebug
     32. hikey960_tv-userdebug
     33. hikey_tv-userdebug
     34. m_e_arm-userdebug
     35. mini_emulator_arm64-userdebug
     36. mini_emulator_x86-userdebug
     37. mini_emulator_x86_64-userdebug
     38. poplar-eng
     39. poplar-user
     40. poplar-userdebug
     41. uml-userdebug
Which would you like? [aosp_arm-eng] 26

编译目标格式说明

编译目标的格式:BUILD-BUILDTYPE,比如上面的 poplar-eng 的 BUILD 是 poplar,BUILDTYPE 是 eng.

什么是 BUILD

BUILD 指的是特定功能的组合的特定名称,即表示编译出的镜像可以运行在什么环境。其中 aosp(Android Open Source Project)代表 Android 开源项目;arm 表示系统是运行在 arm 架构的处理器上,arm64 则是指 64 位 arm 架构处理器,x86 则表示 x86 架构的处理器,更多设备代码和编译目标参考官方文档

什么是 BUILDTYPE

BUILDTYPE 则指的是编译类型,通常有三种:

  • user:用来正式发布到市场的版本,权限受限,如没有 root 权限,不能 dedug 等。
  • userdebug:在user版本的基础上开放了 root 权限和 debug 权限。
  • eng:代表 engineer,开发工程师的版本,拥有最大的权限(root等),具有额外调试工具的开发配置。

如果没有谷歌手机设备,可以选择 arm 或者 x86,我选择了 aosp_x86-eng,编译完后运行模拟器看看,因此这里选择序号 26。

开始编译

通过 make 指令进行代码编译:

代码语言:javascript
复制
make -j8

其中 -jN 参数表示处理并行任务,通常使用的任务数 N 介于编译时所用计算机上硬件线程数的 1-2 倍之间。

查看计算机上的核心数:

代码语言:javascript
复制
cat /proc/cpuinfo | grep processor
processor	: 0
processor	: 1
processor	: 2
processor	: 3

可看到创建的虚拟机 CPU 核心共有 4 个,那么要实现最快的编译速度,可以使用介于 make -j4 到 make -j8 之间的命令。

不出意外,当看到:#### build completed successfully (03:55:24 (hh:mm:ss)) ####就整编成功了。

运行模拟器

整编完,网上很多都是说直接运行命令:emulator,但是我报以下错误了:

代码语言:javascript
复制
emulator: WARNING: Couldn't find crash service executable /media/ubuntu/disk/Project/AOSP9/prebuilts/android-emulator/linux-x86_64/emulator64-crash-service
emulator: WARNING: system partition size adjusted to match image file (1080 MB > 800 MB)
queryCoreProfileSupport: swap interval not found
failed to create drawable
failed to create drawable
failed to create drawable
failed to create drawable
failed to create drawable
failed to create drawable
failed to create drawable
failed to create drawable
getGLES2ExtensionString: Could not make GLES 2.x context current!

第一个警告不管,第二个警告可以 emulator 加参数 -partition-size 2048解决,也可以不管,最后一个折腾了很久,可以加参数-gpu off,完整运行模拟器的命令:emulator -gpu off -partition-size 2048,这时应该又会报:

代码语言:javascript
复制
emulator: WARNING: Couldn't find crash service executable /media/ubuntu/disk/Project/AOSP9/prebuilts/android-emulator/linux-x86_64/emulator64-crash-service
emulator: WARNING: system partition size adjusted to match image file (1338 MB > 800 MB)
emulator: ERROR: Running multiple emulators with the same AVD is an experimental feature.
Please use -read-only flag to enable this feature.

只能重启一下才能解决。

如果编译完成后启动模拟器时卡在黑屏,可以尝试编译其他的!

emulator 还有很多参数,可以用 emulator -help 查看,参数如下:

代码语言:javascript
复制
-sysdir <dir> 为模拟器在<dir>目录中搜索系统硬盘镜像
-system <file> 为模拟器从<file>文件中读取初始化系统镜像
-datadir <dir> 设置用户数据写入的目录
-kernel <file> 为模拟器设置使用指定的模拟器内核
-ramdisk <file> 设置内存RAM 镜像文件(默认为<system>/ramdisk.img)
-image <file> 废弃,使用-system <file> 替代
-init-data <file> 设置初始化数据镜像(默认为<system>/userdata.img)
-initdata <file> 和"-init-data <file>"使用方法一致
-data <file> 设置数据镜像(默认为<datadir>/userdata-qemu.img)
-partition-size <size> system/data 分区容量大小(MB)
-cache <file> 设置模拟器缓存分区镜像(默认为零时文件)
-no-cache 禁用缓存分区
-nocache 与"-no-cache"使用方法相同
-sdcard <file> 指定模拟器SDCard 镜像文件(默认为<system>/sdcard.img)
-wipe-data 清除并重置用户数据镜像(从initdata 拷贝)
-avd <name> 指定模拟器使用Android 虚拟设备
-skindir <dir> 设置模拟器皮肤在<dir>目录中搜索皮肤(默认为<system>/skins 目录)
-skin <name> 选择使用给定的皮肤
-no-skin 不适用任何模拟器皮肤
-noskin 使用方法与"-no-skin"相同
-memory <size> 物理RAM 内存大小(MB)
-netspeed <speed> 设置最大网络下载、上传速度
-netdelay <delay> 网络时延模拟
-netfast 禁用网络形态
-tarce <name> 代码配置可用
-show-kernel 显示内核信息
-shell 在当前终端中使用根Shell 命令
-no-jni Dalvik 运行时禁用JNI 检测
-nojni 使用方法与"-no-jni"相同
-logcat <tag> 输出给定tag 的Logcat 信息
-no-audio 禁用音频支持
-noaudio 与"-no-audio"用法相同
-audio <backend> 使用指定的音频backend
-audio-in <backend> 使用指定的输入音频backend
-audoi-out <backend> 使用指定的输出音频backend
-raw-keys 禁用Unicode 键盘翻转图
-radio 重定向无线模式接口到个性化设备
-port <port> 设置控制台使用的TCP 端口
-ports <consoleport>,<adbport> 设置控制台使用的TCP 端口和ADB 调试桥使用的TCP 端口
-onion <image> 在屏幕上层使用覆盖PNG 图片
-onion-alpha <%age> 指定上层皮肤半透明度
-onion-rotation 0|1|2|3 指定上层皮肤旋转
-scale <scale> 调节模拟器窗口尺寸(三种:1.0-3.0、dpi、auto)
-dpi-device <dpi> 设置设备的resolution (dpi 单位) (默认165)
-http-proxy <proxy> 通过一个HTTP 或HTTPS 代理来创建TCP 连接
-timezone <timezone> 使用给定的时区,而不是主机默认的
-dns-server <server> 在模拟系统上使用给定的DNS 服务
-cpu-delay <cpudelay> 调节CUP 模拟
-no-boot-anim 禁用动画来快速启动
-no-window 禁用图形化窗口显示
-version 显示模拟器版本号
-report-console <socket> 向远程socket 报告控制台端口
-gps <device> 重定向GPS 导航到个性化设备
-keyset <name> 指定按键设置文件名
-shell-serial <device> 根shell 的个性化设备
-old-system 支持旧版本(pre 1.4)系统镜像
-tcpdump <file> 把网络数据包捕获到文件中
-bootchart <timeout> bootcharting 可用
-qemu args.... 向qemu 传递参数
-qemu -h 显示qemu 帮助
-verbose 和"-debug-init"相同
-debug <tags> 可用、禁用调试信息
-debug-<tag> 使指定的调试信息可用
-debug-no-<tag> 禁用指定的调试信息
-help 打印出该帮助文档
-help-<option> 打印出指定option 的帮助文档
-help-disk-images 关于硬盘镜像帮助
-help-keys 支持按钮捆绑(手机快捷键)
-help-debug-tags 显示出-debug <tag>命令中的tag 可选值
-help-char-devices 个性化设备说明
-help-environment 环境变量
-help-keyset-file 指定按键绑定设置文件
-help-virtula-device 虚拟设备管理
补充

补充

模拟器运行需要四个文件,分别是:

  • Linux Kernel
  • system.img
  • userdata.img
  • ramdisk.img

上面我 lunch 命令时选择的是 aosp_x86-eng,因此 linux 默认使用的 AOSP/prebuilds/qemu-kernel/x86/kernel-qemu 下的 kernel-qemu,而其他文件则是使用的 AOSP/out/target/product/generic_x86 目录下的 system.img、userdata.img、ramdisk.img。

单编

单编就是编译某个模块,比如 Setting,会在 out 目录对应的产品有 Settings.apk,例如:out/target/product/generic_x86/system/priv-app/Settings/Settings.apk,这是可以直接安装的。

1、source build/envsetup.sh

2、lunch

3、选择单编版本序号

4、编译

4.1、mmm

代码语言:javascript
复制
mmm packages/apps/Settings/

编译指定目录下的模块,但不编译它所依赖的其它模块。

4.2、mm

先进入目录:

代码语言:javascript
复制
cd packages/apps/Settings/

再编译

代码语言:javascript
复制
mm

编译当前目录下的模块,它和 mmm 一样,不编译依赖模块。

4.3、mma

编译当前目录下的模块及其依赖项。

4.4、mmma [module_path]

编译指定路径下所有模块,且包含依赖

4.5、make

make: 不带任何参数则是编译整个系统

代码语言:javascript
复制
make MediaProvider

单个模块编译,会把该模块及其依赖的其他模块一起编译,会搜索整个源代码来定位 MediaProvider 模块所使用的 Android.mk 文件,还要判断该模块依赖的其他模块是否有修改。

make snod

如果我们修改代码,想看效果,怎么办?

1、可以在编译完成后,借助 adb install -r apk路径直接将生成的 apk 文件安装到设备上,如果不是 APK,直接 push 对应的文件。

2、可以编译好完成后,再使用make snod,重新生成 system.img,再运行模拟器也可。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-07-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 整编
    • 初始化编译环境
      • 选择编译目标
        • 编译目标格式说明
      • 开始编译
        • 运行模拟器
          • 补充
      • 单编
        • make snod
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档