第一:执行环境变量的sh脚本:
我们先执行:
. build/envsetup.shincluding device/generic/car/vendorsetup.sh
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including device/generic/uml/vendorsetup.sh
including device/qcom/common/vendorsetup.sh
including vendor/qcom/proprietary/common/vendorsetup.sh
including sdk/bash_completion/adb.bash
打印出来的信息是执行最后的此代码来实现的.
# 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 | sort` \`test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \`test -d product && find -L product -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`
doecho "including $f". $f
done
unset f
我们查看一下vi device/qcom/common/vendorsetup.sh文件:
30 add_lunch_combo msm8974-userdebug31 add_lunch_combo msm8610-userdebug
................................................................57 add_lunch_combo sdm710-userdebug58 add_lunch_combo msmnile-userdebug59 add_lunch_combo qcs605-userdebug60 add_lunch_combo XXX-user61 add_lunch_combo XXX-userdebug62 add_lunch_combo XXX-eng
看到这个眼熟不,这就是我们添加自定义项目时添加的内容.
我们再看看第一个方法hmm,都是我们常用的命令说明:
function hmm() {
cat <<EOF
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.
- provision: Flash device with all required partitions. Options will be passed on to fastboot.
- 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.
- mgrep: Greps on all local Makefiles files.
- sepgrep: Greps on all local sepolicy files.
- sgrep: Greps on all local source files.
- godir: Go to the directory containing a file.Environment options:
- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note thatASAN_OPTIONS=detect_leaks=0 will be set by default until thebuild is leak-check clean.Look at the source to view more functions. The complete list is:
EOFlocal T=$(gettop)local A=""local ifor i in `cat $T/build/envsetup.sh | sed -n "/^[[:blank:]]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; doA="$A $i"doneecho $A
}
我们再查看lunch方法:
function lunch()
{local answerif [ "$1" ] ; thenanswer=$1elseprint_lunch_menuecho -n "Which would you like? [aosp_arm-eng] "read answerfilocal selection=if [ -z "$answer" ]thenselection=aosp_arm-engelif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")thenif [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]thenselection=${LUNCH_MENU_CHOICES[$(($answer-1))]}fielseselection=$answerfiexport TARGET_BUILD_APPS=local product variant_and_version variant versionproduct=${selection%%-*} # Trim everything after first dashvariant_and_version=${selection#*-} # Trim everything up to first dashif [ "$variant_and_version" != "$selection" ]; thenvariant=${variant_and_version%%-*}if [ "$variant" != "$variant_and_version" ]; thenversion=${variant_and_version#*-}fifiif [ -z "$product" ]thenechoecho "Invalid lunch combo: $selection"return 1fiTARGET_PRODUCT=$product \TARGET_BUILD_VARIANT=$variant \TARGET_PLATFORM_VERSION=$version \build_build_var_cacheif [ $? -ne 0 ]thenreturn 1fiexport TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)if [ -n "$version" ]; thenexport TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)elseunset TARGET_PLATFORM_VERSIONfiexport TARGET_BUILD_TYPE=releaseechoset_stuff_for_environmentprintconfigdestroy_build_var_cache
}
第二:执行编译项目
lunch project_name-userdebug============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=8.1.0
TARGET_PRODUCT=XXX
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_PLATFORM_VERSION=OPM1
TARGET_BUILD_APPS=
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=kryo300
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv7-a-neon
TARGET_2ND_CPU_VARIANT=cortex-a9
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.16.0-30-generic-x86_64-with-Ubuntu-14.04-trusty
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=OPM1.171019.026
OUT_DIR=out
AUX_OS_VARIANT_LIST=
============================================
在这,我们可以看到许多定义的环境变量值,如:
PLATFORM_VERSION=8.1.0
TARGET_PRODUCT=XXX
TARGET_BUILD_VARIANT=userdebug
我们要查看这些变量值,直接执行如下命令:
echo $TARGET_BUILD_VARIANT
userdebug
下面是这些常用的变量值:
echo $ANDROID_PRODUCT_OUT
/hde/hexm/XXX_codes_20180626/LINUX/android/out/target/product/XXX
echo $ANDROID_BUILD_TOP
/hde/hexm/XXX_codes_20180626/LINUX/android
echo $JAVA_HOME
/usr/lib/jvm/java-8-openjdk-amd64
echo $QCPATH
vendor/qcom/proprietary
第三步:make
当我们执行make时,会查找当前的Makefie文件或者makefile文件并且执行,在android顶级源码目录下面,确实有个Makefile,它之后一行内容:
### DO NOT EDIT THIS FILE ###
include build/core/main.mk
### DO NOT EDIT THIS FILE ###
因此,执行的是build/core/main.mk文件.
参考资料:
(1)android编译系统分析一:source build/envsetup.sh与lunch
https://blog.csdn.net/u011913612/article/details/51878356
(2)Android编译系统分析三:make完整编译android系统
https://blog.csdn.net/u011913612/article/details/52434411