免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1780 | 回复: 0
打印 上一主题 下一主题

Android源码学习(5)Android编译系统之envsetup.sh [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-23 02:09 |只看该作者 |倒序浏览
根据Android源码学习(4)在Ubuntu11.04上编译Android所示步骤,我们已经成功编译了Android源码、并通过模拟器成功运行了Android。接下来,将开始漫长的的源码学习之旅。但是,面对如此庞大的项目(将近2G的源码),我们该从如何入手呢?几年的程序员经验让我觉得,每当面对一个全新项目时,从项目的编译系统入手,对于理解项目的功能,代码组织结构起到至关重要的作用。

Android通过Git对源码进行版本管理。目前Android一共包含一百多个项目,编译系统就是其中最为重要的一个项目。它的所有脚本位于Android源码根目录的build目录下。




回想Android源码学习(4)在Ubuntu11.04上编译Android所提到的源码编译的第一步,即执行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. Look at the source to view more functions. The complete list is:
  12. 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. You're building on Linux

  3. Lunch menu... pick a combo:
  4. 1. generic-eng
  5. 2. simulator
  6. 3. full_passion-userdebug
  7. 4. full_crespo4g-userdebug
  8. 5. full_crespo-userdebug

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

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP