Android系统编译前的准备工作,我个人认为由如下三个步骤完成。接下来,我就逐一分析每一步骤都干了什么事情。
1、安装jdk、设置环境变量JAVA_HOME。
2、source build/envsetup.sh
3、lunch <product_name>-<build_variant>
###################################################
博文中出现的get_abs_build_var() 和 get_build_var()请移步到 这里
1、设置JAVA_HMOE环境变量
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2、source build/envsetup.sh
该shell脚本实现了许多有用的shell函数,可通过执行hmm命令查看(hmm是envsetup.sh实现的第一个shell函数)。
下面是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.
- sgrep: Greps on all local source files.
- godir: Go to the directory containing a file.
除了上面实现的shell函数,envsetup.sh还把device和vendor目录下的所有vendorsetup.sh脚本包含进来了。最后,还调用shell函数addcompletions。
if [ "x$SHELL" != "x/bin/bash" ]; then
case `ps -o command -p $$` in # $$属于Special Shell Variables,表示Process ID of shell
*bash*)
;;
*)
echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
;;
esac
fi
# Execute the contents of any vendorsetup.sh files we can find.
for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
`test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
do
echo "including $f"
. $f # source找到的所有vendorsetup.sh文件
done
unset f
addcompletions # 检查bash版本,并source sdk/bash_completion目录下的所有[a-z]*.bash文件
$$ 请查看
Special Shell Variables
vendorsetup.sh的内容大多数是调用add_lunch_combo函数添加<product_name>-<build_variant>格式的lunch选项(也可以实现一些shell functions)。如:
add_lunch_combo aosp_flounder-userdebug
接下来,看一下add_lunch_combo函数的实现,File:build/envsetup.sh。
# Clear this variable. It will be built up again when the vendorsetup.sh
# files are included at the end of this file.
unset LUNCH_MENU_CHOICES
function add_lunch_combo()
{
local new_combo=$1
local c
for c in ${LUNCH_MENU_CHOICES[@]} ; do
if [ "$new_combo" = "$c" ] ; then
return
fi
done
LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo) # vendorsetup.sh中添加的combo选项都保存在数组LUNCH_MENU_CHOICES中
}
我们回到envsetup.sh脚本的最后一行,看一下addcompletio