Android编译环境搭建

Android编译环境搭建
  • 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
http://source.android.com/source/building.html

Android官方源码下载
Installing Repo
  1. Make sure you have a bin/ directory in your home directory and that it is included in your path:

    $ mkdir ~/bin $ PATH=~/bin:$PATH 
  2. 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

  1. 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
  2. Run repo init to 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-number
    To 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
http://source.android.com/source/downloading.html

Android源码其他获取方式
1、解决方案提供商
2、Soc开源社区www.linaro.org

Android源码目录结构
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 核心库相关

Android源码编译

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,编译,环境搭建)