- A Linux or Mac system. The Android build is routinely tested in house on recent versions of Ubuntu LTS (10.04), but most distributions should have the required build tools available.
- 30GB or more of disk space in order to build the Android tree.
- A 64-bit environment is required for Gingerbread (2.3.x) and newer versions, including the master branch. You can compile older versions on 32-bit systems.
- Python 2.6 -- 2.7
- GNU Make 3.81 -- 3.82
- JDK 6 if you wish to build Gingerbread or newer; JDK 5 for Froyo or older.
- Git 1.7 or newer
$ sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \
libxml2-utils xsltproc
-
Make sure you have a bin/ directory in your home directory and that it is included in your path:
$ mkdir ~/bin $ PATH=~/bin:$PATH -
Download the Repo tool and ensure that it is executable:
$ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo $ chmod a+x ~/bin/repo
Initializing a Repo client
-
Create an empty directory to hold your working files. If you're using MacOS, this has to be on a case-sensitive filesystem. Give it any name you like:
$ mkdir WORKING_DIRECTORY $ cd WORKING_DIRECTORY -
Run
repo initto bring down the latest version of Repo with all its most recent bug fixes. You must specify a URL for the manifest, which specifies where the various repositories included in the Android source will be placed within your working directory.$ repo init -u https://android.googlesource.com/platform/manifest
http://source.android.com/source/build-numbers.html choose a build-numberTo check out a branch other than "master", specify it with -b:
$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
Downloading the Android Source Tree
To pull down the Android source tree to your working directory from the repositories as specified in the default manifest, run
$ repo sync
| abi | application binary interface |
| bionic | C Runtime:libc libm libdl dynamic linker Bionic含义为仿生,这里面是一些基础的库的源代码 |
| bootloader/legacy | Bootloader reference code启动引导相关代码 |
| build | Build System,build目录中存放的是编译系统mk文件,编译规则和generic产品基础配置文件 |
| cts | Android兼容性测试套件标准 |
| dalvik | Dalvik Virtual Machine |
| development | High-level development and debugging tools,程序开发所需要的模板和工具,如AVD,实例代码 |
| device | 设备相关代码 |
| framework | Core Android app framework libraries 核心框架--java及C++语言,是Android应用程序的框架 |
| hardware | 主要是硬件适配层HAL代码 |
| ndk | ndk(Android NativeDevelopment Kit)相关代码 |
| out | 编译完成后的输出目录 |
| prebuilt | Binaries to support Linux and Mac OS builds,x86和arm架构下预编译的一些资源 |
| package | Android的各种系统级应用程序 |
| sdk | SDK 工具源码及qemu相关源码 |
| system | Android根文件系统相关源码,如:init、adb、toolbox及一些库 |
| docs | 介绍开源的相关文档 |
| external | Android使用的一些开源的模块代码 |
| libcore | 核心库相关 |
Initialize
Initialize the environment with the envsetup.sh script. Note that replacing "source" with a single dot saves a few characters, and the short form is more commonly used in documentation.
$ source build/envsetup.sh
or
$ . build/envsetup.sh
Choose a Target
Choose which target to build with lunch. The exact configuration can be passed as an argument, e.g.
$ lunch aosp_arm-eng
The example above refers to a complete build for the emulator, with all debugging enabled.
If run with no arguments lunch will prompt you to choose a target from the menu.
All build targets take the form BUILD-BUILDTYPE, where the BUILD is a codename referring to the particular feature combination. Here's a partial list:
| Build name | Device | Notes |
|---|---|---|
| aosp_arm | ARM emulator | AOSP, fully configured with all languages, apps, input methods |
| aosp_maguro | maguro | AOSP, running on Galaxy Nexus GSM/HSPA+ ("maguro") |
| aosp_panda | panda | AOSP, running on PandaBoard ("panda") |
and the BUILDTYPE is one of the following:
| Buildtype | Use |
|---|---|
| user | limited access; suited for production |
| userdebug | like "user" but with root access and debuggability; preferred for debugging |
| eng | development configuration with additional debugging tools |
For more information about building for and running on actual hardware, see Building for Devices.
Build the Code
Build everything with make. GNU make can handle parallel tasks with a -jN argument, and it's common to use a number of tasks N that's between 1 and 2 times the number of hardware threads on the computer being used for the build. E.g. on a dual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core), the fastest builds are made with commands between make -j16 and make -j32.
$ make -j4

本文档详细介绍了如何搭建Android编译环境,包括所需的基础工具安装、官方源码下载、初始化环境、选择编译目标等步骤,并提供了Android源码目录结构的说明。
2万+

被折叠的 条评论
为什么被折叠?



