Android Porting Book--Android Build System
2010-08-24 15:08
495 查看
Android
Build System
Understanding
the makefile
Layers
Building
the Android Platform
Building
the Android Kernel
Build
Variants
Android
uses a custom build system to generate tools, binaries, and
documentation. This document provides an overview of Android's build
system and instructions for doing a simple build.
Android's
build system is make based and requires a recent version of GNU Make
(note that Android uses advanced features of GNU Make that may not
yet appear on the GNU Make web site). Before continuing, check your
version of make by running
If you don't have version 3.80 or greater, you need to upgrade
your version of make.
A
makefile defines how to build a particular application. Makefiles
typically include all of the following elements:
Name:
Give your build a name (
Local
Variables: Clear local variables with CLEAR_VARS (
Files:
Determine which files your application depends upon
(
Tags:
Define tags, as necessary (
Libraries:
Define whether your application links with other libraries
(
Template
file: Include a template file to define underlining make tools for
a particular target (
The
following snippet illustrates a typical makefile.
The
snippet above includes artificial line breaks to maintain a
print-friendly document.
The
build hierarchy includes the abstraction layers described in the
table below.
Each
layer relates to the one above it in a one-to-many relationship. For
example, an arch can have more than one board and each board can
have more than one device. You may define an element in a given
layer as a specialization of an element in the same layer, thus
eliminating copying and simplifying maintenance.
This
section describes how to build the default version of Android. Once
you are comfortable with a generic build, then you can begin to
modify Android for your own target device.
To
do a generic build of android, source
which contains necessary variable and function definitions, as
described below.
You
can also replace user with eng for a debug engineering build:
These Build
Variants differ
in terms of debug options and packages installed.
Execute
clean up the binaries you just created. You can also execute
get rid of the binaries of all combos.
equivalent to removing the
where all generated files are stored.
The
binaries of each combo are stored as distinct sub-directories
of
making it possible to quickly switch between combos without having
to recompile all sources each time.
However,
performing a clean rebuild is necessary if the build system doesn't
catch changes to environment variables or makefiles. If this happens
often, you should define the
variable as shown below:
Doing
so will force the build system to use the ccache compiler cache
tool, which reduces recompiling all sources.
are provided in
don't need to get installed on your system.
The
following error is likely caused by running an outdated version of
Java.
a Java program that uses facilities first made available in Java
version 1.5. Check your version of Java by executing
the shell you use to build. You should see something like:
If
you do have Java 1.5 or later and your receive this error, verify
that you have properly updated your
This
section describes how to build Android's default kernel. Once you
are comfortable with a generic build, then you can begin to modify
Android drivers for your own target device.
To
build the kernel base, switch to the device directory
(
in order to establish variables and run:
Then
switch to the kernel directory
The
default branch is always
To check out a different branch, execute the following:
To
simplify code management, give your local branch the same name as
the remote branch it is tracking (as illustrated in the snippet
above). Switch between branches by executing
Find
out which branches exist (both locally and remotely) and which one
is active (marked with an asterisk) by executing the following:
To
only see local branches, omit the
To
build the kernel, execute:
When
building for a particular product, it's often useful to have minor
variations on what is ultimately the final release build. These are
the currently-defined build variants:
If
you build one flavor and then want to build another, you should
run
the two makes to guarantee that you don't pick up files installed by
the previous flavor.
also suffice, but it takes a lot longer.
Build System
In this
document
Understandingthe makefile
Layers
Building
the Android Platform
Building
the Android Kernel
Build
Variants
Android
uses a custom build system to generate tools, binaries, and
documentation. This document provides an overview of Android's build
system and instructions for doing a simple build.
Android's
build system is make based and requires a recent version of GNU Make
(note that Android uses advanced features of GNU Make that may not
yet appear on the GNU Make web site). Before continuing, check your
version of make by running
% make -v.
If you don't have version 3.80 or greater, you need to upgrade
your version of make.
Understanding
the makefile
Amakefile defines how to build a particular application. Makefiles
typically include all of the following elements:
Name:
Give your build a name (
LOCAL_MODULE := <build_name>).
Local
Variables: Clear local variables with CLEAR_VARS (
include $(CLEAR_VARS)).
Files:
Determine which files your application depends upon
(
LOCAL_SRC_FILES := main.c).
Tags:
Define tags, as necessary (
LOCAL_MODULE_TAGS := eng development).
Libraries:
Define whether your application links with other libraries
(
LOCAL_SHARED_LIBRARIES := cutils).
Template
file: Include a template file to define underlining make tools for
a particular target (
include $(BUILD_EXECUTABLE)).
The
following snippet illustrates a typical 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
The
snippet above includes artificial line breaks to maintain a
print-friendly document.
Layers
Thebuild hierarchy includes the abstraction layers described in the
table below.
Each
layer relates to the one above it in a one-to-many relationship. For
example, an arch can have more than one board and each board can
have more than one device. You may define an element in a given
layer as a specialization of an element in the same layer, thus
eliminating copying and simplifying maintenance.
Layer | Example | Description |
---|---|---|
Product | myProduct, myProduct_eu, myProduct_eu_fr, j2, sdk | The product layer defines a complete specification of a shipping product, defining which modules to build and how to configure them. You might offer a device in several different versions based on locale, for example, or on features such as a camera. |
Device | myDevice, myDevice_eu, myDevice_eu_lite | The device layer represents the physical layer of plastic on the device. For example, North American devices probably include QWERTY keyboards whereas devices sold in France probably include AZERTY keyboards. Peripherals typically connect to the device layer. |
Board | sardine, trout, goldfish | The board layer represents the bare schematics of a product. You may still connect peripherals to the board layer. |
Arch | arm (arm5te) (arm6), x86, 68k | The arch layer describes the processor running on your board. |
Building
the Android Platform
Thissection describes how to build the default version of Android. Once
you are comfortable with a generic build, then you can begin to
modify Android for your own target device.
Device
Code
Todo a generic build of android, source
build/envsetup.sh,
which contains necessary variable and function definitions, as
described below.
% cd $TOP % . build/envsetup.sh # pick a configuration using choosecombo % choosecombo % make -j4 PRODUCT-generic-user
You
can also replace user with eng for a debug engineering build:
% make -j4 PRODUCT-generic-eng
These Build
Variants differ
in terms of debug options and packages installed.
Cleaning
Up
Execute % m cleanto
clean up the binaries you just created. You can also execute
% m clobberto
get rid of the binaries of all combos.
% m clobberis
equivalent to removing the
//out/directory
where all generated files are stored.
Speeding
Up Rebuilds
Thebinaries of each combo are stored as distinct sub-directories
of
//out/,
making it possible to quickly switch between combos without having
to recompile all sources each time.
However,
performing a clean rebuild is necessary if the build system doesn't
catch changes to environment variables or makefiles. If this happens
often, you should define the
USE_CCACHEenvironment
variable as shown below:
% export USE_CCACHE=1
Doing
so will force the build system to use the ccache compiler cache
tool, which reduces recompiling all sources.
ccachebinaries
are provided in
//prebuilt/...and
don't need to get installed on your system.
Troubleshooting
Thefollowing error is likely caused by running an outdated version of
Java.
device Dex: core UNEXPECTED TOP-LEVEL ERROR: java.lang.NoSuchMethodError: method java.util.Arrays.hashCode with signature ([Ljava.lang.Object;)I was not found. at com.google.util.FixedSizeList.hashCode(FixedSizeList.java:66) at com.google.rop.code.Rop.hashCode(Rop.java:245) at java.util.HashMap.hash(libgcj.so.7) [...]
dxis
a Java program that uses facilities first made available in Java
version 1.5. Check your version of Java by executing
% java -versionin
the shell you use to build. You should see something like:
java version "1.5.0_07" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-164) Java HotSpot(TM) Client VM (build 1.5.0_07-87, mixed mode, sharing)
If
you do have Java 1.5 or later and your receive this error, verify
that you have properly updated your
PATHvariable.
Building
the Android Kernel
Thissection describes how to build Android's default kernel. Once you
are comfortable with a generic build, then you can begin to modify
Android drivers for your own target device.
To
build the kernel base, switch to the device directory
(
/home/joe/android/device)
in order to establish variables and run:
% . build/envsetup.sh % partner_setup generic
Then
switch to the kernel directory
/home/joe/android/kernel.
Checking
Out 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"
To
simplify code management, give your local branch the same name as
the remote branch it is tracking (as illustrated in the snippet
above). Switch between branches by executing
% git checkout <branchname>.
Verifying
Location
Findout which branches exist (both locally and remotely) and which one
is active (marked with an asterisk) by executing the following:
% git branch -a android * android-mydevice origin/HEAD origin/android origin/android-mydevice origin/android-mychipset
To
only see local branches, omit the
-aflag.
Building
the Kernel
Tobuild the kernel, execute:
% make -j4
Build
Variants
Whenbuilding for a particular product, it's often useful to have minor
variations on what is ultimately the final release build. These are
the currently-defined build variants:
eng | This is the default flavor. A plain makeis the same as make eng. Installs modules tagged with: eng, debug, user, and/or development. Installs non-APK modules that have no tags specified. Installs APKs according to the product definition files, in addition to tagged APKs. ro.secure=0 ro.debuggable=1 ro.kernel.android.checkjni=1 adbis enabled by default. |
user | make user This is the flavor intended to be the final release bits. Installs modules tagged with user. Installs non-APK modules that have no tags specified. Installs APKs according to the product definition files; tags are ignored for APK modules. ro.secure=1 ro.debuggable=0 adbis disabled by default. |
userdebug | make userdebug The same as user, except: Also installs modules tagged with debug. ro.debuggable=1 adbis enabled by default. |
you build one flavor and then want to build another, you should
run
make installcleanbetween
the two makes to guarantee that you don't pick up files installed by
the previous flavor.
make cleanwill
also suffice, but it takes a lot longer.
相关文章推荐
- ANDROID Porting系列三、Build Cookbook
- Rockie's Android Porting Guide(4)——Add SD card to your system
- Android /system/build.prop 文件
- Android build system & Android.mk 规范
- Rockie's Android Porting Guide(1)——Build your own board
- 【Android7.1.2源码解析系列】Android编译系统翻译------Android_Build_System(/build/core/build-system.html)
- Android通过SystemProperties获取build.prop中配置的信息
- Android build system note
- Android build system note
- Rockie's Android Porting Guide(4)——Add SD card to your system
- Android Makefile and build system 分析与梳理
- how to write one native program based on android source build system
- Android build system & Android.mk 规范
- Android NDK开发指南(三)Android build system & Android.mk 规范
- Rockie's Android Porting Guide(2)——Add USB WIFI to your system
- Android build system ---转
- android build 过程 (ramdisk.img、system.img、userdata.img)和 启动过程简单分析
- Android 中文翻译:Build System Overview
- Android中/system/build.prop文件解读
- Rockie's Android Porting Guide(4)——Add SD card to your system