Android使用一个可定制的编译系统来生成工具、二进制文件和文档。本文档简单介绍了这个编译系统,并做一个简单编译的例子。 Android的编译系统基于MAKE,并需要一个较新版本的GNU MAKE,你可以通过make -v来检查你机器上的MAKE程序的版本号,确保它高于或等于3.80。 一、理解makefile 一个makefile定义了怎么样编译一个特定的应用程序,一般包含下面几个元素: 1、名字:你要编译的模块的名字(LOCAL_MODULE := <build_name>) 2、本地变量:清除本地变量(include $(CLEAR_VARS)) 3、文件:列出你的程序依赖的文件(LOCAL_SRC_FILES := main.c) 4、标记:如果必要的话,定义标记(LOCAL_MODULE_TAGS := eng development) 5、库:定义你的程序依赖的库(LOCAL_SHARED_LIBRARIES := cutils) 6、模板文件:调用一个模板文件来编译特定目标(include $(BUILD_EXECUTABLE)) 下面演示了一个典型的makefile LOCAL_PATH := $(my-dir) include $(CLEAR_VARS) LOCAL_MODULE := <buil_name> LOCAL_SRC_FILES := main.c LOCAL_MODULE_TAGS := eng development LOCAL_SHARED_LIBRARIES := cutils include $(BUILD_EXECUTABLE) (HOST_)EXECUTABLE, (HOST_)JAVA_LIBRARY, (HOST_)PREBUILT, (HOST_)SHARED_LIBRARY, (HOST_)STATIC_LIBRARY, PACKAGE, JAVADOC, RAW_EXECUTABLE, RAW_STATIC_LIBRARY, COPY_HEADERS, KEY_CHAR_MAP 二、抽象层次 下面的表格描述了编译系统中的抽象层次。 每一层与它的上一层都是一对多的关系。如,一个arch可以有多个board,一个board可以有多个device。每一层中,你可以定义多个不同特征的元素,可以使用一样的代码支持多个不同的需求。


Layer

Example

Description

Product

myProduct,myProduct_eu, myProduct_eu_fr, j2, sdk

The product layerdefines a complete specification of a shipping product, definingwhich modules to build and how to configure them. You might offera device in several different versions based on locale, forexample, or on features such as a camera.

产品层定义了一个商业产品的完整特征,比如编译哪个模块,怎么配置它们。

Device

myDevice,myDevice_eu, myDevice_eu_lite

The device layerrepresents the physical layer of plastic on the device. Forexample, North American devices probably include QWERTY keyboardswhereas devices sold in France probably include AZERTY keyboards.Peripherals typically connect to the device layer.

设备层代表设备的物理层。比如,北美的设备包含一个QWERTY键盘,而法国的设备有一个AZERTY键盘。

Board

sardine, trout,goldfish

The board layerrepresents the bare schematics of a product. You may still connectperipherals to the board layer.

Arch

arm (arm5te)(arm6), x86, 68k

The arch layerdescribes the processor running on your board.

这个层次描述了运行在board上的处理器。

% m clean
% m clobber
/home/joe/android/kernel
CheckingOut a Branch

Thedefault branch is always android.To check out a different branch, execute the following:

% git checkout --track -b android-mydevice origin/android-mydevice
  //Branch android-mydevice set up to track remote branch
% refs/remotes/origin/android-mydevice.
  //Switched to a new branch "android-mydevice"

Tosimplify code management, give your local branch the same name as theremote branch it is tracking (as illustrated in the snippet above).Switch between branches by executing %git checkout <branchname>.

VerifyingLocation

Findout which branches exist (both locally and remotely) and which one isactive (marked with an asterisk) by executing the following:

% git branch -a
  android
* android-mydevice
  origin/HEAD
  origin/android
  origin/android-mydevice
  origin/android-mychipset

Toonly see local branches, omit the -a flag.

编译内核时,运行% make -j4

五、编译变量

eng

This is thedefault flavor. A plain make isthe same as makeeng.

  • Installsmodules tagged with: engdebuguser,and/or development.
  • Installsnon-APK modules that have no tags specified.
  • InstallsAPKs according to the product definition files, in addition totagged APKs.
  • ro.secure=0
  • ro.debuggable=1
  • ro.kernel.android.checkjni=1
  • adb isenabled by default.
  • 这个是默认风格。只执行make相当于执行makeeng。
  • 安装标记为engdebuguser的模块和development。
  • 安装没有标记的非APK模块。
  • 安装产品定义文件中描述的APK和标记过的APK。
  • adb默认打开。

user

makeuser

This is theflavor intended to be the final release bits.

  • Installsmodules tagged with user.
  • Installsnon-APK modules that have no tags specified.
  • InstallsAPKs according to the product definition files; tags are ignoredfor APK modules.
  • ro.secure=1
  • ro.debuggable=0
  • adb isdisabled by default.
  • 发布版使用的风格。
  • 安装标记为user的模块。
  • 安装没有标记的非APK模块。
  • 安装产品定义文件中定义的APK,对APK来说,标记被忽略
  • adb默认关闭。

userdebug

makeuserdebug

The same as user,except:

  • Alsoinstalls modules tagged with debug.
  • ro.debuggable=1
  • adb isenabled by default.
  • user基本相同,除了以下几点:
  • 安装标记为debug的模块。
  • adb默认打开。
make installclean