android编译分析【一】

来源:互联网 发布:js监听手机软键盘事件 编辑:程序博客网 时间:2024/05/21 00:54

最近以CM7为基础移植android到某个机型,简单的说编译步骤如下:


1,在device/zte/blade/目录下运行unzip-files.sh,这步的主要目的是将某些硬件相关的库直接复制到vendor目录(因为拿不到厂家的源码只能这样做了);

2,在source目录运行. build/envsetup.sh;

3,lunch,选取适当的编译目标;

4,make -jx,开跑。


一切从envsetup.sh开始,在运行了build/envsetup.sh之后,将会多出一堆有用的函数来帮助我们更好的编译或者分析android,在输入help之后会显示:

Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:- 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.- mmm:     Builds all of the modules in the supplied directories.- cgrep:   Greps on all local C/C++ files.- jgrep:   Greps on all local Java files.- resgrep: Greps on all local res/*.xml files.- godir:   Go to the directory containing a file.Look at the source to view more functions. The complete list is:add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant cproj croot findmakefile gdbclient get_abs_build_var getbugreports get_build_var getprebuilt gettop godir help isviewserverstarted jgrep lunch m mm mmm pid printconfig print_lunch_menu resgrep runhat runtest set_java_home setpaths set_sequence_number set_stuff_for_environment settitle smoketest startviewserver stopviewserver systemstack tapas tracedmdump
其中的各项功能可以参照英文解说,croot可以从各种目录下随时回到source目录,mm根据当前路径的Makefile编译出模块,mmm根据后面跟着的path来寻找makefile,然后把makefile里面定义了的LOCAL_MODULE编译出来。

build/envsetup.sh的工作大部分就是定义上述的一些helper函数,最后运行的就是这一段:

# add the default one hereadd_lunch_combo generic-eng# if we're on linux, add the simulator.  There is a special case# in lunch to deal with the simulatorif [ "$(uname)" = "Linux" ] ; then    add_lunch_combo simulatorfi    ...# Execute the contents of any vendorsetup.sh files we can find.for f in `/bin/ls vendor/*/vendorsetup.sh vendor/*/build/vendorsetup.sh device/*/*/vendorsetup.sh 2> /dev/null`do    echo "including $f"    . $fdoneunset f

因此,在默认情况下会有generic-eng这个选项,在linux下编译的话会再有simulator选项,然后就会到vendor和device目录中寻找vendorsetup.sh然后执行,以ZTE blade的CM7为例,在device/zte/blade中有vendorsetup.sh文件,内容如下:

add_lunch_combo zte_blade-engadd_lunch_combo zte_blade-userdebug
它会再增加zte_blade-eng和zte_blade-userdebug两个目标。
随后的lunch根据上述的目标生成菜单供选择,lunch与choosecombo达到的效果一样,只不过choosecombo是把选择细化成几个步骤。

通过lunch完成选择后输出如下信息:

============================================PLATFORM_VERSION_CODENAME=RELPLATFORM_VERSION=2.3.5TARGET_PRODUCT=zte_bladeTARGET_BUILD_VARIANT=engTARGET_SIMULATOR=falseTARGET_BUILD_TYPE=releaseTARGET_BUILD_APPS=TARGET_ARCH=armHOST_ARCH=x86HOST_OS=linuxHOST_BUILD_TYPE=releaseBUILD_ID=GINGERBREAD============================================
其中记录了本次编译的主要配置,此后可以通过printconfig命令显示。