1.下载过Android整套源代码的亲应该很熟悉的一个操作就是product编译前的几个步骤,

source build/envsetup.sh

lunch $ComboName

make -j4

2.那么第一步source的envsetup.sh有些什么作用呢?让我们来看一下envsetup.sh中的内容,

其实其就是一些shell脚本方法的集合,方便平台debug的开发者的一些日常工作。如果要

查阅该脚本都提供了哪些方法可以在source之后直接hmm查看帮助:

$ hmm
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- lunch: lunch <product_name>-<build_variant>
- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]
- croot: Changes directory to the top of the tree.
- 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.
- cgrep: Greps on all local C/C++ files.
- ggrep: Greps on all local Gradle files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- mangrep: Greps on all local AndroidManifest.xml files.
- sepgrep: Greps on all local sepolicy files.
- sgrep: Greps on all local source files.
- godir: Go to the directory containing a file.

Environemnt options:
- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
ASAN_OPTIONS=detect_leaks=0 will be set by default until the
build is leak-check clean.

Look at the source to view more functions. The complete list is:

addcompletions add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant core coredump_enable coredump_setup cproj croot findmakefile get_abs_build_var getbugreports get_build_var getdriver getlastscreenshot get_make_command getprebuilt getscreenshotpath getsdcardpath gettargetarch gettop ggrep godir hmm is isviewserverstarted jgrep key_back key_home key_menu lunch _lunch m make mangrep mgrep mm mma mmm mmma pez pid printconfig print_lunch_menu qpid rcgrep resgrep runhat runtest sepgrep set_java_home setpaths set_sequence_number set_stuff_for_environment settitle sgrep smoketest stacks startviewserver stopviewserver systemstack tapas tracedmdump treegrep

如上显示,还是有挺多方便的方法的,当然如果想研究下各个shell方法怎么实现的直接查看envsetup.sh中的源码就好了。

3.lunch之后呢就会打印一些可以选择进行编译的Combo(product)的名称,选择一个进行lunch,那么这里的combo是哪儿来的呢?

从上面的第一步执行输出中可以看到会include一系列的vendorsetup.sh,例如:

includingdevice/moto/shamu/vendorsetup.sh

vi device/moto/shamu/vendorsetup.sh 可以看到如下内容,在这里添加了一个combo项,如下:

add_lunch_combo aosp_shamu-userdebug #通过add_lunch_combo方法将product(aosp_shamu-userdebug)添加到LUNCH_MENU_CHOICES中

在每一个Board目录下会有一个vendorsetup.sh,其主要作用就是用来添加produnct combo选项的,即其确定了本board可以编译出

哪些product。那么在第一步Source build下的envsetup.sh,可以看到envsetup.sh最后几行脚本会去查找device和vendor目录

下所有的vendorsetup.sh文件,并include该文件


lunch方法的实现也是在envsetup.sh中实现的,只执行lunch,会打印出lunch menu(combo list)供选择。

lunch product的时候可以直接输入product对应的combo number也可以直接输入combo name

eg. lunch 2

lunchaosp_shamu-userdebug

lunch会根据输入的参数去查找product对应的编译文件,确定所选择的编译combo是否能够进行编译,已经读取该combo对应的编译变量,配置JAVA_HOME

,PATH,GCC相关路径等内容

4.make -j4 多线程编译

这一步即可启动你所选择的combo(product)进行编译了,那么熟悉make的亲应该知道此时 make会其找当前目录中的makefile,那么从Android源码根目录就会找到

Makefile,其为make编译的入口,其中一句将编译程序指定如下:

include build/core/main.mk

研究编译系统,从这个main.mk开始,从main.mk中看到编译系统的源码实现主要在build/core和build/vendor目录下 ,

BUILD_SYSTEM := $(TOPDIR)build/core

BUILD_SYSTEM_VENDOR := $(TOPDIR)build/vendor


这里是最基础的源码编译步骤,Android编译系统的内容后续从main.mk开始研究并记录笔记~~



更多相关文章

  1. android客户端xmpp & smack & openfire简单开发实例
  2. android 通过Intent使用Bundle传递对象
  3. Rexsee API介绍:Android(安卓)WakeLock进程持续,阻止应用休眠
  4. Android关于Activity屏蔽/拦截Home键
  5. android手机屏幕横竖屏切换禁止调用生命周期函数方法
  6. 【android】 百度地图应用开发(一)
  7. Unity头像上传功能实现 二
  8. Ruby实现Android自动化屏幕适配
  9. 深入浅出Android(安卓)Handler

随机推荐

  1. Android 应用程序开关GPS
  2. 【转】android开源项目---项目篇
  3. Android Intent study
  4. 高手速成android开源项目【developer篇】
  5. Android Handler的使用
  6. [置顶] 我的Android进阶之旅------>Ubunt
  7. cocos2d-x调用android内嵌浏览器打开网页
  8. Android(安卓)积累
  9. 7.0 Android系统修改默认输入法后,切换系
  10. 在Eclipse添加Android兼容包( v4、v7 app