Android编译系统之 envsetup.sh

Androi源码编译的第一步,即执行envsetup.sh(sources build/envsetup.sh)脚本,初始化环境变量。可见envsetup.sh在整个Android编译系统所扮演的重要角色。

脚本envsetup.sh的主要作用是添加编译系统所需的环境变量以及一些方便Android开发的shell命令到当前shell。在执行envsetup.sh脚本后,可以通过如下命令来查看新加的变量及命令:

  1. ~/android/source/build$ . envsetup.sh
  2. ~/android/source/build$ set |less

在Android源码目录下,也可以通过如下命令查看新添加的shell命令:

  1. ~/android/source$ help
  2. Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
  3. - croot: Changes directory to the top of the tree.
  4. - m: Makes from the top of the tree.
  5. - mm: Builds all of the modules in the current directory.
  6. - mmm: Builds all of the modules in the supplied directories.
  7. - cgrep: Greps on all local C/C++ files.
  8. - jgrep: Greps on all local Java files.
  9. - resgrep: Greps on all local res/*.xml files.
  10. - godir: Go to the directory containing a file.
  11.  
  12. Look at the source to view more functions. The complete list is:
  13. 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

下面将比较常用的shell命令逐一解释:

  • croot
    改变当前路径到Android源码的根目录
  • m
    编译整个Android项目
  • mm
    编译当前目录下所有的模块
  • mmm
    编译通过参数指定的模块,例如mmm dalvik/dexdump
  • cgrep
    查询当前目录及子目录下所有符合查询条件的C文件(*.c, *.cc, *.cpp, *.h)
  • jgrep
    查询当前目录及子目录下所有符合查询条件的JAVA文件(*.java)
  • resgrep
    查询当前目录及子目录下所有资源相关的文件(*.xml)
  • lunch
    选择编译的目标
  • printconfig
    输出类似如下格式的当前配置
    1. ============================================
    2. PLATFORM_VERSION_CODENAME=REL
    3. PLATFORM_VERSION=2.3.5
    4. TARGET_PRODUCT=generic
    5. TARGET_BUILD_VARIANT=eng
    6. TARGET_SIMULATOR=
    7. TARGET_BUILD_TYPE=release
    8. TARGET_BUILD_APPS=
    9. TARGET_ARCH=arm
    10. HOST_ARCH=x86
    11. HOST_OS=linux
    12. HOST_BUILD_TYPE=release
    13. BUILD_ID=GINGERBREAD
    14. ============================================

在开始编译之前,还需要通过如下shell命令lunch选择编译目标:

  1. ~/android/source$ lunch
  2.  
  3. You're building on Linux
  4.  
  5. Lunch menu... pick a combo:
  6. 1. generic-eng
  7. 2. simulator
  8. 3. full_passion-userdebug
  9. 4. full_crespo4g-userdebug
  10. 5. full_crespo-userdebug
  11.  
  12. Which would you like? [generic-eng]

如上所示,当前共有5种编译目标类型可供选择。其中generic-eng和simulator属于系统默认的编译目标类型,后面三种则是从vendor/*/vendorsetup.sh、vendor/*/build/vendorsetup.sh和device/*/*/vendorsetup.sh的文件中读取的。

编译目标类型由两部分构成,中间以"-"分隔。前半部分称之为编译名字,后半部分称之为编译类型。

目前Android一共包含3种编译类型,可以通过如下命令查看:

  1. ~/android/source/build$ set |grep “VARIANT_CHOICES=”
  2. VARIANT_CHOICES=([0]="user" [1]="userdebug" [2]="eng")
  • eng
    应该是engineering的缩写,属于适合开发的编译类型。
    安装所有标记eng,user,debug或者development的模块
    安装所有没有标记的非APK模块
    按照产品定义文件安装APK模块
    ro.secure=0
    ro.debuggable=1
    ro.kernel.android.checkjni=1
    激活adb
  • user
    编译适合用户使用的最终版本。
    安装标记为user的模块
    安装所有没有标记的非APK模块
    按照产品定义文件安装APK模块
    ro.secure=1
    ro.debuggable=0
    禁止adb
  • userdebug
    除了以下几点,其他和user一样
    安装标记为debug的模块
    ro.debuggable=1
    激活adb
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值