博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android 编译(1)——Android编译步骤梳理
阅读量:4029 次
发布时间:2019-05-24

本文共 5777 字,大约阅读时间需要 19 分钟。

文章目录

Android编译步骤

1 source build/envsetup.sh

2 lunch xxx-eng/xxx-userdebug 选择要编译的平台选项配置
3 make 编译

envsetup.sh

Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:- lunch:   lunch 
-
- tapas: tapas [
...] [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.

执行. build/envsetup.sh或者source build/envsetup.sh还有添加下面这些命令到当前环境下:

# Get the value of a build variable as an absolute path.function get_abs_build_var()# Get the exact value of a build variable.function get_build_var()# check to see if the supplied product is one we can buildfunction check_product()# check to see if the supplied variant is validfunction check_variant()function setpaths()function printconfig()function set_stuff_for_environment()function set_sequence_number()function settitle()function addcompletions()function choosetype()function choosevariant()function choosecombo()function add_lunch_combo()function print_lunch_menu()function gettop...

除此之外还会包含device目录和vendor目录下的vendorsetup.sh

# 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"    . $fdoneunset f
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.shincluding device/generic/mini-emulator-arm64/vendorsetup.shincluding device/lge/hammerhead/vendorsetup.shincluding device/lge/mako/vendorsetup.shincluding device/htc/flounder/vendorsetup.sh

vendorsetup.sh

vendorsetup.sh的内容是添加的是编译平台的选项配置,如下,调用add_lunch_combo命令添加对应的编译选项:

add_lunch_combo m_e_arm-userdebug

add_lunch_combo命令

# 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_CHOICESfunction 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)}

lunch命令

lunch命令会打印当前检索到的lunch选项,解析传入的编译选项,检查对应的product和variant,配置对应的环境变量:

TARGET_PRODUCT
TARGET_BUILD_VARIANT
TARGET_BUILD_TYPE

function lunch(){    local answer    if [ "$1" ] ; then        answer=$1    else        print_lunch_menu        echo -n "Which would you like? [aosp_arm-eng] "        read answer    fi    local selection=    if [ -z "$answer" ]    then        selection=aosp_arm-eng    elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")    then        if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]        then            selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}        fi    elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")    then        selection=$answer    fi    if [ -z "$selection" ]    then        echo        echo "Invalid lunch combo: $answer"        return 1    fi    export TARGET_BUILD_APPS=        local product=$(echo -n $selection | sed -e "s/-.*$//")    check_product $product    if [ $? -ne 0 ]    then        echo        echo "** Don't have a product spec for: '$product'"        echo "** Do you have the right repo manifest?"        product=    fi    local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")    check_variant $variant    if [ $? -ne 0 ]    then        echo        echo "** Invalid variant: '$variant'"        echo "** Must be one of ${VARIANT_CHOICES[@]}"        variant=    fi    if [ -z "$product" -o -z "$variant" ]    then        echo        return 1    fi	//解析完传入的编译选项后,配置环境变量    export TARGET_PRODUCT=$product    export TARGET_BUILD_VARIANT=$variant    export TARGET_BUILD_TYPE=release    echo    set_stuff_for_environment    printconfig}

环境变量TARGET_PRODUCT的解析过程可以参考如下文章:

<
>https://www.cnblogs.com/leaven/p/4337887.html

Android Makefile解析TARGET_PRODUCT后得到PRODUCT_DEVICE,并赋值给TARGET_DEVICE。

通过TARGET_DEVICE,编译系统配置了目标系统的编译属性、决定了目标文件的输出路径、添加了指定目录下的编译文件。

以上是从编译的角度解析了Android的PRODUCT,分析了编译系统是如何解析我们的特定的Product。

正向添加Android Product的可以参考如下文章:

<<01 Android系统之添加Product>>https://blog.csdn.net/feit2417/article/details/105189947

Android makefile

inherit函数

1、继承通过$1参数传入的所有变量;

2、在 .INHERITS_FROM 变量中记录下这些继承关系;
3、在 ALL_PRODUCTS 变量中标识出已经被访问过的节点。

## $(1): product to inherit## Does three things:#  1. Inherits all of the variables from $1.#  2. Records the inheritance in the .INHERITS_FROM variable#  3. Records that we've visited this node, in ALL_PRODUCTS#define inherit-product  $(foreach v,$(_product_var_list), \      $(eval $(v) := $($(v)) $(INHERIT_TAG)$(strip $(1)))) \  $(eval inherit_var := \      PRODUCTS.$(strip $(word 1,$(_include_stack))).INHERITS_FROM) \  $(eval $(inherit_var) := $(sort $($(inherit_var)) $(strip $(1)))) \  $(eval inherit_var:=) \  $(eval ALL_PRODUCTS := $(sort $(ALL_PRODUCTS) $(word 1,$(_include_stack))))endef
device/companyName/platformName/device.mk
$(call inherit-product, frameworks/native/build/tablet-7in-hdpi-1024-dalvik-heap.mk)

TBC

你可能感兴趣的文章
[关注大学生]李开复给中国计算机系大学生的7点建议
查看>>
[关注大学生]大学毕业生择业:是当"鸡头"还是"凤尾"?
查看>>
[茶余饭后]10大毕业生必听得歌曲
查看>>
gdb调试命令的三种调试方式和简单命令介绍
查看>>
C++程序员的几种境界
查看>>
VC++ MFC SQL ADO数据库访问技术使用的基本步骤及方法
查看>>
VUE-Vue.js之$refs,父组件访问、修改子组件中 的数据
查看>>
Vue-子组件改变父级组件的信息
查看>>
Python自动化之pytest常用插件
查看>>
Python自动化之pytest框架使用详解
查看>>
【正则表达式】以个人的理解帮助大家认识正则表达式
查看>>
性能调优之iostat命令详解
查看>>
性能调优之iftop命令详解
查看>>
非关系型数据库(nosql)介绍
查看>>
移动端自动化测试-Windows-Android-Appium环境搭建
查看>>
Xpath使用方法
查看>>
移动端自动化测试-Mac-IOS-Appium环境搭建
查看>>
Selenium之前世今生
查看>>
Selenium-WebDriverApi接口详解
查看>>
Selenium-ActionChains Api接口详解
查看>>