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

整编

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

初始化编译环境

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

source build/envsetup.sh

选择编译目标

命令:

lunch

输出:

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 指令进行代码编译:

make -j8

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

查看计算机上的核心数:

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,但是我报以下错误了:

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,这时应该又会报:

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 查看,参数如下:

-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

mmm packages/apps/Settings/

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

4.2、mm

先进入目录:

cd packages/apps/Settings/

再编译

 mm

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

4.3、mma

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

4.4、mmma [module_path]

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

4.5、make

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

make MediaProvider

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

make snod

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

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

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

公众号

我的公众号:吴小龙同学,欢迎交流~

AOSP 源码整编单编的更多相关文章

  1. Android Studio 导入 AOSP 源码

    有了 AOSP 源码,接下来就是如何看了,可以直接文本看,可以用 Source Insight,我当然选择 Android Studio,Android Studio 是我熟悉且十分强大的工具.问题来 ...

  2. 将AOSP源码导入到Android Studio进行查看

    生成iml和ipr文件 source build/envsetup.sh lunch aosp_x86-eng # 或者直接输入lunch,然后选择对应的target make idegen deve ...

  3. Android 5.1 AOSP 源码获取

    本文已同步更新至:http://dxjia.cn/2015/08/android-aosp-code-sync/ Android 5.1源码开放有一个多月啦,但由于城墙的关系,每次想着更新最新源码学习 ...

  4. Elasticsearch源码分析 | 单节点的启动和关闭

    本文主要简要介绍Elasticsearch单节点的启动和关闭流程.Elasticsearch版本:6.3.2 相关文章 1.Google Guice 快速入门 2.Elasticsearch 中的 G ...

  5. AOSP 源码下载

    网上关于这块大部分教程都是无效的,因为墙的缘故,无法使用官方提供的下载链接,我这里使用了清华大学的镜像,是能够顺利将 AOSP 下载下来.如果你还没有安装 Ubuntu,请看<VirtualBo ...

  6. Spring 源码学习 - 单例bean的实例化过程

    本文作者:geek,一个聪明好学的同事 1. 简介 开发中我们常用@Commpont,@Service,@Resource等注解或者配置xml去声明一个类,使其成为spring容器中的bean,以下我 ...

  7. 【转】提供android 5.0 AOSP源码下载

    http://blog.csdn.net/innost/article/details/41148335 android-5.0.tar.gz 115网盘礼包码:5lbcl16a1k7q http:/ ...

  8. Ubuntu 18.04编译AOSP源码

    总结一下我从Ubuntu 18.04下编译成功AOSP的过程,以及遇到的坑 我的电脑配置: OS: Ubuntu 18.04 bionic Kernel: x86_64 Linux 4.18.0-17 ...

  9. spring事务详解(三)源码详解

    系列目录 spring事务详解(一)初探事务 spring事务详解(二)简单样例 spring事务详解(三)源码详解 spring事务详解(四)测试验证 spring事务详解(五)总结提高 一.引子 ...

随机推荐

  1. freemarker常用标签解释三

    1 date,time,datetime 日期,时间,时间日期 <#assign test1 = "10/25/1995"?date("MM/dd/yyyy&quo ...

  2. react 中文文档案例四 (登陆登出按钮)

    import React from 'react'; import ReactDOM from 'react-dom'; class LoginControl extends React.Compon ...

  3. 解决maven项目中有小红叉的问题

    首先在window--perferences--showview中显示problems中查看出错的原因

  4. Android 远程连接数据库。。。。。

    本来是 6.0.6  换成mysql 5.1.14 驱动ok.... 将方法 放在 new Thread() 解决..... 只能在主线程绘制ui.... 解决办法...子Thread 获取数据后,将 ...

  5. Margarite and the best present

    Little girl Margarita is a big fan of competitive programming. She especially loves problems about a ...

  6. HDU 3652 区间有13并且这样整除13 的数量(数位DP)

    题目:求1-n的范围里含有13且能被13整除的数字的个数. 分析: dfs(len, num, mod, flag) mod记录数字对13取余后的值 len表示当前位数 num==0 不含13且上一位 ...

  7. linux mysql下载地址

    linux mysql下载地址: https://dev.mysql.com/downloads/mysql/5.7.html#downloads

  8. Android 选择本地图片的demo

    https://github.com/lipanquan/SelectLocalPhoto

  9. Linux多线程及线程同步简单实例

    一.多线程基本概念 1. 线程的基本概念 ① 线程就是轻量级的进程 ②线程和创建他的进程共享代码段.数据段 ③线程拥有自己的栈 2. 在实际应用中,多个线程往往会访问同一数据或资源,为避免线程之间相互 ...

  10. python模块之urllib

    python文档官网地址:https://docs.python.org/3.6/library/urllib.html?highlight=urllib urllib 是一个收集以下模块以处理URL ...