andorid系统配置及编译过程
android系统正以迅雷不及掩耳之势冲击着智能手机与平板电脑市场,它颠覆了传统手机的概念,将手机与平板电脑进行了一次大洗牌,最可贵的是他的开放性(虽不是完全开放)吸引了一大批工程师去改造它,完善它,任何人都可以下载到它的源代码一睹它的真面目。这一节讲讲这样从头配置一个属于你的android系统,至于如何获取android源代码这里就不讲了。本文是在假设你已经从android官网上获取了其源代码的基础上讲解的。
1.Create a company directory in //vendor/.
mkdir vendor/<company_name>
这一步是先在vendor(供货商) 下新建一个目录,用你公司名字命名,没有的公司的就随便编一个吧(:
2.Create a products directory beneath the company directory you created in step 1.
mkdir vendor/<company_name>/products/
同上,创建一个目录,用你产品的名字命名吧
3.Create a product-specific makefile, called vendor/<company_name>/products/<first_product_name>.mk, that includes at least the following code:
$(call inherit-product, $(SRC_TARGET_DIR)/product/generic.mk)
#
# Overrides
PRODUCT_NAME := <first_product_name>
PRODUCT_DEVICE := <board_name>
在/products/ 目录下建立一个mk文件,内容格式如上所示,拿个mini6410.mk的例子给大家看看:
$(call inherit-product, $(SRC_TARGET_DIR)/product/generic.mk)
# Overrides
PRODUCT_MANUFACTURER := FriendlyARM
PRODUCT_BRAND := FriendlyARM
PRODUCT_NAME := mini6410
PRODUCT_DEVICE := mini6410
***************************************************
mini6410.mk的路径为/Android-2.2/vendor/friendly-arm/products/mini6410.mk l;这也验证了上述1,2两步。
4.在上述*.mk文件中添加可选的定义,这个就不多说了。
5.In the products directory, create an AndroidProducts.mk file that point to (and is responsible for finding) the individual product make files.
#
# This file should set PRODUCT_MAKEFILES to a list of product makefiles
# to expose to the build system. LOCAL_DIR will already be set to
# the directory containing this file.
#
# This file may not rely on the value of any variable other than
# LOCAL_DIR; do not use any conditionals, and do not look up the
# value of any variable that isn't set in this file or in a file that
# it includes.
#
PRODUCT_MAKEFILES := /
$(LOCAL_DIR)/first_product_name.mk /
按照这个模板添加就是了。
6.Create a board-specific directory beneath your company directory that matches the PRODUCT_DEVICE variable <board_name> referenced in the product-specific make file above. This will include a make file that gets accessed by any product using this board.
mkdir vendor/<company_name>/<board_name>
在你公司的目录下添加一个目录,名字命名为板子的名字,如:Android-2.2/vendor/friendly-arm/mini6410,其中mini6410就是开发板的名字,这个目录下的文件比较重要。接下来为了好叙述,就借用mini6410的例子吧。
7.在Android-2.2/vendor/friendly-arm/mini6410目录下创建BoardConfig.mk文件
先看看这个文件的内容是怎样的:
Android以模块的形式来组织各个系统中的部件,Eng专业点的词汇就是Module,就是各位在几乎每个目录下都能看到的Android.mk。可以简单地把Android所有的Make文件分为4种:
在实际的过程中,我们也可以自己编辑out目录下的生成文件,然后手工打包相应生成相应的img,最常用的是加入一些需要集成进的prebuilt file。
所有的Makefile都通过build/core/main.mk这个文件组织在一起,它定义了一个默认goals:droid,当我们在TOP目录下敲Make实际上就等同于我们执行make droid。当Make include所有的文件,完成对所有make我文件的解析以后就会寻找生成droid的规则,依次生成它的依赖,直到所有满足的模块被编译好,然后使用相应的工具打包成相应的img。
基本上Android building system就是以这样一种方式组织在一起的了,下面说一点闲散的东西。首先是如何来加快Android的编译过程,因为每次Android都要遍历所有的Android.mk,不管是编译整个工程还是只编译某个模块。所以可以将遍历的结果保存下来,下次直接从文件读就好了,但是这里容易出错,所以一定要确认是否正确包含了所有的.mk,当新加入文件的时候确认将原来保存的文件删除。下面是我写的加快编译的一个makefile,将下面的语句替换掉 main.mk中的相应部分就可以了:
FROM:
subdir_makefiles += /
$(shell build/tools/findleaves.sh --prune="./out" $(subdirs) Android.mk)
TO:
ifneq ($(ONE_SHOT_MAKEFILE),)
else
ifneq ($(CASH_MK),true)
subdir_makefiles += /
$(shell build/tools/findleaves.sh --prune="./out" $(subdirs) Android.mk)
else
subdir-makefiles-cash := $(shell cat build/subdir_mk_cash)
ifeq ($(subdir-makefiles-cash),)
$(warning No .mk cash ,create now !)
subdir_makefiles += /
$(shell build/tools/findleaves.sh --prune="./out" $(subdirs) Android.mk)
mk-to-file := $(shell echo $(subdir_makefiles) > build/subdir_mk_cash)
else
$(warning Using cash mk !)
subdir_makefiles := $(shell cat build/subdir_mk_cash)
endif
endif
endif
通过CASH_MK=true来打开快速编译的功能,因为没有对错误进行检测的操作,所以使用的时候一定要特别小心。
最后一个是扩展SDK API的问题,Android可以编译出自己的SDK,并扩展相应的SDK API,现在没有仔细的研究,只了解一个粗暴的方法就是在frameworks/base/core/java中添加相应的类。