Android Build (1) -- Source Code Build Steps

来源:互联网 发布:爱知中学录取分数线 编辑:程序博客网 时间:2024/04/29 09:51

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,例如:

  including device/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

        lunch aosp_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开始研究并记录笔记~~



  

0 0
原创粉丝点击