欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

android8.1 source build/envsetup.sh分析 增加删除lunch

程序员文章站 2022-07-02 15:30:26
...

https://blog.csdn.net/weixin_39694445/article/details/84753142

Android 编译过程

1.  初始化参数设置  环境变量

2.  检查环境变量  配置目标环境(导入luncher)

3.  选择lunch  读取目标配置平台信息(分支特性、文件)

4.  清空输出目录

5.  执行编译

6.  打包


source build/envsetup.sh  分析

1.  加载编译命令

- 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.

执行后是这样的

[email protected]:~/godv/AOSP/android-8.1.0_r1$ source build/envsetup.sh 
including device/asus/fugu/vendorsetup.sh
including 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-mips64/vendorsetup.sh
including device/generic/mini-emulator-mips/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/google/dragon/vendorsetup.sh
including device/google/marlin/vendorsetup.sh
including device/google/muskie/vendorsetup.sh
including device/google/taimen/vendorsetup.sh
including device/huawei/angler/vendorsetup.sh
including device/lge/bullhead/vendorsetup.sh
including device/linaro/hikey/vendorsetup.sh
including sdk/bash_completion/adb.bash

2.  加载平台信息

[email protected]:~/godv/AOSP/android-8.1.0_r1$ lunch 

You're building on Linux

Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_arm64-eng
     3. aosp_mips-eng
     4. aosp_mips64-eng
     5. aosp_x86-eng
     6. aosp_x86_64-eng
     7. full_fugu-userdebug
     8. aosp_fugu-userdebug
     9. aosp_car_emu_arm-userdebug
     10. aosp_car_emu_arm64-userdebug
     11. aosp_car_emu_x86-userdebug
     12. aosp_car_emu_x86_64-userdebug
     13. mini_emulator_arm64-userdebug
     14. m_e_arm-userdebug
     15. m_e_mips64-eng
     16. m_e_mips-userdebug
     17. mini_emulator_x86_64-userdebug
     18. mini_emulator_x86-userdebug
     19. uml-userdebug
     20. aosp_dragon-userdebug
     21. aosp_dragon-eng
     22. aosp_marlin-userdebug
     23. aosp_marlin_svelte-userdebug
     24. aosp_sailfish-userdebug
     25. aosp_walleye-userdebug
     26. aosp_walleye_test-userdebug
     27. aosp_taimen-userdebug
     28. aosp_angler-userdebug
     29. aosp_bullhead-userdebug
     30. aosp_bullhead_svelte-userdebug
     31. hikey-userdebug
     32. hikey960-userdebug

Which would you like? [aosp_arm-eng] 

这里打开  build/envsetup.sh  分析 lunch函数  可以发现lunch后面的选择项是由LUNCH_MENU_CHOICES提供的

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))]}
        ...
}

LUNCH_MENU_CHOICES  是在add_lunch_combo()中被添加进去的 也就是说add_lunch_combo()就是添加lunch分支

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

在执行了  source build/envsetup.sh  后会  including device/asus/fugu/vendorsetup.sh  这些脚本  会发现这些脚本本质上就是调用add_lunch_combo来添加lunch分支的

#
# Copyright 2013 The Android Open Source Project
...

add_lunch_combo full_fugu-userdebug
add_lunch_combo aosp_fugu-userdebug

执行lunch 6  OUT_DIR  输出目录

PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=8.1.0
TARGET_PRODUCT=aosp_x86_64
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_PLATFORM_VERSION=OPM1
TARGET_BUILD_APPS=
TARGET_ARCH=x86_64
TARGET_ARCH_VARIANT=x86_64
TARGET_CPU_VARIANT=
TARGET_2ND_ARCH=x86
TARGET_2ND_ARCH_VARIANT=x86_64
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.15.0-142-generic-x86_64-with-Ubuntu-16.04-xenial
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=OPM1.171019.011
OUT_DIR=out
AUX_OS_VARIANT_LIST=

继续执行  export   查看当前环境变量

...
declare -x ANDROID_BUILD_TOP="/home/godv/godv/AOSP/android-8.1.0_r1"
declare -x ANDROID_DEV_SCRIPTS="/home/godv/godv/AOSP/android-8.1.0_r1/development/scripts:/home/godv/godv/AOSP/android-8.1.0_r1/prebuilts/devtools/tools:/home/godv/godv/AOSP/android-8.1.0_r1/external/selinux/prebuilts/bin:/home/godv/godv/AOSP/android-8.1.0_r1/prebuilts/misc/linux-x86/dtc:/home/godv/godv/AOSP/android-8.1.0_r1/prebuilts/misc/linux-x86/libufdt"
declare -x ANDROID_EMULATOR_PREBUILTS="/home/godv/godv/AOSP/android-8.1.0_r1/prebuilts/android-emulator/linux-x86_64"
declare -x ANDROID_HOST_OUT="/home/godv/godv/AOSP/android-8.1.0_r1/out/host/linux-x86"
declare -x ANDROID_HOST_OUT_TESTCASES="/home/godv/godv/AOSP/android-8.1.0_r1/out/host/linux-x86/testcases"
declare -x ANDROID_JAVA_TOOLCHAIN="/usr/lib/jvm/java-8-openjdk-amd64/bin"
declare -x ANDROID_PRE_BUILD_PATHS="/usr/lib/jvm/java-8-openjdk-amd64/bin:"
declare -x ANDROID_PRODUCT_OUT="/home/godv/godv/AOSP/android-8.1.0_r1/out/target/product/generic_x86_64"
...

不同的分支下面有sh中对应的mk  里面配置了不同的命令