最近以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 here add_lunch_combo generic-eng # if we're on linux, add the simulator. There is a special case # in lunch to deal with the simulator if [ "$(uname)" = "Linux" ] ; then add_lunch_combo simulator fi ... # 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" . $f done unset f
add_lunch_combo zte_blade-eng add_lunch_combo zte_blade-userdebug它会再增加zte_blade-eng和zte_blade-userdebug两个目标。
通过lunch完成选择后输出如下信息:
============================================ PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=2.3.5 TARGET_PRODUCT=zte_blade TARGET_BUILD_VARIANT=eng TARGET_SIMULATOR=false TARGET_BUILD_TYPE=release TARGET_BUILD_APPS= TARGET_ARCH=arm HOST_ARCH=x86 HOST_OS=linux HOST_BUILD_TYPE=release BUILD_ID=GINGERBREAD ============================================其中记录了本次编译的主要配置,此后可以通过printconfig命令显示。