Android编译环境进行初始化


我们完成AOSP源码下载之后,就可以准备源码进行编译了。但编译之前,首先要对编译环境进行初始化工作。

在这个过程中,主要是指定编译的类型和目标设备的型号。

Android的编译类型主要有eng、userdebug和user三种,而支持的目标设备型号则是不确定的,它们由当前的源码配置情况所决定。为了确定源码支持的所有目标设备型号,Android编译系统在初始化的过程中,需要在特定的目录中加载特定的配置文件。

清除缓存(如果需要的话)

如果之前执行过编译工作,或者编译出错了,可以执行清除命令:

$ make clobber

执行envsetup.sh,配置编译环境

打开一个终端(bash),cd到源码根目录,并且将build/envsetup.sh加载到该终端中:

$ source build/envsetup.sh
或
$ . ./build/envsetup.sh
including device/generic/car/vendorsetup.sh
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-mips/vendorsetup.sh
including device/generic/mini-emulator-mips64/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including device/generic/uml/vendorsetup.sh
including device/google/crosshatch/vendorsetup.sh
including device/google/cuttlefish/vendorsetup.sh
including device/google/marlin/vendorsetup.sh
including device/google/muskie/vendorsetup.sh
including device/google/taimen/vendorsetup.sh
including device/linaro/hikey/vendorsetup.sh
including sdk/bash_completion/adb.bash

我们来看命令的输出,文件build/envsetup.sh在加载的过程中又会加载一些其他文件。

  • 在device目录中加载那些名称为vendorsetup.sh的文件。

  • 在sdk/bash_completion目录下的adb.bash文件也会加载到当前终端来。

    它是用来实现adb命令的bash completion功能的。也就是说,加载了该文件之后,我们在运行adb相关的命令的时候,通过按tab键就可以帮助我们自动完成命令的输入。

执行lunch命令

执行命令lunch,选择编译的目标:

$ lunchYou're building on DarwinLunch menu... pick a combo:1. aosp_arm-eng2. aosp_arm64-eng3. aosp_mips-eng4. aosp_mips64-eng5. aosp_x86-eng6. aosp_x86_64-eng7. aosp_car_arm-userdebug8. aosp_car_arm64-userdebug9. aosp_car_x86-userdebug10. aosp_car_x86_64-userdebug11. mini_emulator_arm64-userdebug12. m_e_arm-userdebug13. m_e_mips-userdebug14. m_e_mips64-eng15. mini_emulator_x86-userdebug16. mini_emulator_x86_64-userdebug17. uml-userdebug18. aosp_crosshatch-userdebug19. aosp_blueline-userdebug20. aosp_cf_x86_auto-userdebug21. aosp_cf_x86_phone-userdebug22. aosp_cf_x86_tablet-userdebug23. aosp_cf_x86_tablet_3g-userdebug24. aosp_cf_x86_tv-userdebug25. aosp_cf_x86_wear-userdebug26. aosp_cf_x86_64_auto-userdebug27. aosp_cf_x86_64_phone-userdebug28. aosp_cf_x86_64_tablet-userdebug29. aosp_cf_x86_64_tablet_3g-userdebug30. aosp_cf_x86_64_tv-userdebug31. aosp_cf_x86_64_wear-userdebug32. cf_x86_auto-userdebug33. cf_x86_phone-userdebug34. cf_x86_tablet-userdebug35. cf_x86_tablet_3g-userdebug36. cf_x86_tv-userdebug37. cf_x86_wear-userdebug38. cf_x86_64_phone-userdebug39. cf_x86_64_tablet-userdebug40. cf_x86_64_tablet_3g-userdebug41. cf_x86_64_tv-userdebug42. cf_x86_64_wear-userdebug43. aosp_marlin-userdebug44. aosp_marlin_svelte-userdebug45. aosp_sailfish-userdebug46. aosp_walleye-userdebug47. aosp_walleye_test-userdebug48. aosp_taimen-userdebug49. hikey-userdebug50. hikey64_only-userdebug51. hikey960-userdebug

lunch命令输出了一个Lunch菜单,该菜单列出了当前Android源码支持的所有设备型号及其编译类型。

编译的类型:

  • user: limited access; suited for production(有限的访问权限,一般用于发布版)。
  • eng:具有开发配置,并且有额外的调试工具(注:工程师模式engineer)。
  • userdebug: 这个和user类似,但是可以获取root权限,并且能够调试。

当我们选定了一个Lunch菜单项序号(1-51)之后,按回车键,就可以完成Android编译环境的初始化过程。

注:lunch命令也可以直接这么用 $ lunch aosp_arm-eng

编译环境初始化结果

Android编译环境初始化完成之后,获得了以下三样东西:

  1. 将vendor和device目录下的vendorsetup.sh文件加载到了当前终端。
  2. 新增了lunch、m、mm和mmm等命令。
  3. 通过执行lunch命令设置好了TARGET_PRODUCT、TARGET_BUILD_VARIANT、TARGET_BUILD_TYPE和TARGET_BUILD_APPS等环境变量。

AOSP源码编译


对整个系统进行编译

使用make命令开始整个系统的编译:

make -j8

这里的-j参数后面的数字是编译需要的线程数,建议电脑的CPU数量的1~2倍来设置。

然后就是漫长的等待过程了……

分模块编译

我们也可以用m/mm/mmm/make命令编译源代码。

当然,这要求每一个模块都有一个Android.mk文件。Android.mk实际上是一个Makefile脚本,用来描述模块编译信息。Android编译系统通过整合Android.mk文件完成编译过程。

m、mm和mmm命令也分别是由定义在build/envsetup.sh文件中的函数m、mm和mmm提供的,而这三个函数又都是通过make命令来对源代码进行编译的。

m/mm/mmm使用简介

  • m: Makes from the top of the tree.
  • mm: Builds all of the modules in the current directory, but not their dependencies.
  • mmm: Builds all of the modules in the supplied directories, but not their dependencies.
    To limit the modules being built use the syntax: mmm dir/:target1,target2.
  • mma: Builds all of the modules in the current directory, and their dependencies.
  • mmma: Builds all of the modules in the supplied directories, and their dependencies.

事实上,命令m就是对make命令的简单封装,并且是用来对整个Android源代码进行编译,而命令mm和mmm都是通过make命令来对Android源码中的指定模块进行编译。

m的实现:

function m()
{local T=$(gettop)if [ "$T" ]; then_wrap_build $T/build/soong/soong_ui.bash --make-mode $@elseecho "Couldn't locate the top of the tree.  Try setting TOP."return 1fi
}

当在Android源码中定义的各个模块都编译好之后,我们还需要将编译得到的文件打包成相应的镜像文件,例如system.img、boot.img和recorvery.img等,这样我们才可以将这些镜像烧录到目标设备去运行。

安装系统


系统编译完成之后,我们可以通过使用模拟器来运行,或者使用真机进行刷机。

模拟机启动

$ source build/envsetup.sh
$ lunch //(选择刚才设置的目标版本,例如如果之前我们选择1,那就是aosp_arm-eng)
$ emulator //模拟器启动

刷真机

  1. 进入fastboot模式
$ adb reboot bootloader
  1. 把img文件刷进去
$ fastboot flashall -w  //这个 -w 是为了wipes the /data partition擦除/data分区

**PS:更多精彩内容,请查看 --> 《AOSP 专栏》
**PS:更多精彩内容,请查看 --> 《AOSP 专栏》
**PS:更多精彩内容,请查看 --> 《AOSP 专栏》

Android源码编译过程及刷机过程详解相关推荐

  1. [Android Pro] Android源码编译之Nexus5真机编译

    reference to : http://blog.csdn.net/liu1075538266/article/details/51272398 1.   前言 在Android安全的研究工作中, ...

  2. Android源码编译之Nexus5真机编译

    1.   前言 在Android安全的研究工作中,我们时常要对Android进行改进并对其进行源码编译,由于目前几乎所有的手机厂商均对其底层驱动实行封闭政策,导致我们在完成Android编译后无法将我 ...

  3. 记一次 Android 源码编译刷机过程

    0 背景   为了能在开发设备上运行 adb root 命令得到 root 权限,获得更加强大的调试能力.开发体验,方便以后阅读源码时 Debug 跟踪.进行定制化开发,需要编译 Android 源码 ...

  4. Android 源码编译详解【合集篇】

    Android 源码编译详解[一]:服务器硬件配置及机型推荐 做 Android系统开发多年,开发环境都是入职就搭建好了,入职时拿个账号密码就直接开始搞开发了,年初换了新公司,所有的项目都是刚起步,一 ...

  5. android 编译完后镜像在哪个文件夹,Android源码编译后

    在out/target/product/generic下生成的三个镜像文件:ramdisk.img,system.img,userdata.img以及它们对应的目录树root,system,data. ...

  6. Android源码编译(基于Ubuntu18.0.4)

    文章目录 一.环境搭建 硬件要求 软件要求 操作系统和 JDK 主要软件包 软件安装 Git安装 repo工具安装 安装 openJDK 8 其他依赖安装 二.源码下载 建立源码文件夹 初始化仓库 源 ...

  7. Android源码编译及启动模拟器

    Android源码编译及启动模拟器 源码下载 (1)更改下载源 (2)安装源码下载工具 (3)下载源码 (4)安装环境依赖 源码编译 启动模拟器 源码下载 Ubuntu18.0 (1)更改下载源 源码 ...

  8. Android 源码编译 及 mk文件解读

    Android 源码编译 参考:探索Android FrameWork底层开发视频_哔哩哔哩_bilibili 基础 1.源代码编译 分为2个部分: (1)boot/Kernel (2)Android ...

  9. Android源码编译make的各类错误解决方案汇总

    问题: You are attempting to build with the incorrect version of java.  Your version is: java version & ...

  10. Android 源码编译及常见错误及解决方法

    Android 源码编译及常见错误及解决方法 参考文章: (1)Android 源码编译及常见错误及解决方法 (2)https://www.cnblogs.com/kyyblabla/p/360393 ...

最新文章

  1. python编程print语法_Python 第一节 安装及 print 输出语句—教案
  2. python使用函数的优点-Lambda表达式在Python中的优点和缺点
  3. JAVA .xml 配置和 .properties 配置
  4. java的本地文件操作
  5. 推荐搜索炼丹笔记:向量召回 MIND多兴趣双塔模型
  6. XMLIOC案例-编写spring的Ioc配置
  7. 【设计模式:单例模式】使用单例模式加载properties文件
  8. jdbc thin连接oracle10,setSavepoint方法报错解决办法
  9. android 好玩的ui,让安卓更好玩 这些Launchers值得拥有
  10. 3.5.2 冒泡排序类
  11. Integer 与 int 的区别
  12. linux如何导入安装包,linux下安装pip以及导入第三方包
  13. caf格式 android,实例:Android Studio3+版本 获取存有ANR信息的traces.txt文件,解决ANR问题...
  14. Java 多线程(八) 线程状态图
  15. 高仿大漠找字FindStr
  16. 【matlab 图像处理】图像锐化
  17. 软考高级的信息系统项目管理师零基础好考吗?
  18. Kinect2.0-Python调用-PyKinect2
  19. 申请加精—ERP实施方法论的比较(SAP、 Oracle、J.D.E、BANN、用友等实施方法论)...
  20. 数据分析之numpy基础/matplotlib绘图/numpy常用函数/杂项功能

热门文章

  1. 十大著名黑客——李纳斯-托瓦兹
  2. 用友U8 cloud释放新动能,加速城投行业数智化转型
  3. 体绘制加速技术之数据异步传输
  4. linux游戏掌机,一起来猎奇:窄众平板/游戏掌机推荐
  5. 最新财报发布+天猫618双榜第一,耐克蓄力领跑下个50年
  6. OAI搭建 eNB(2018-09最新版)
  7. uniapp连接手机端调试
  8. Shell及Linux三剑客grep、sed、awk
  9. 手机浏览器打不开php,php 判断是否是手机浏览器访问?
  10. 中兴通讯专利技术价值超450亿元