Getting Started

  • Initializing the Build Environment
  • Downloading the Source
  • Building and Running
  • Building for Devices

Navigating the Source

  • Platform Overview
  • Branches & Releases
  • Build Numbers
  • Browse Source

Contributing

  • Life of a Patch
  • Submitting Patches
  • Life of a Bug
  • Reporting Bugs

Reference

  • Version Control
    • Repo Commands
    • Git Resources
  • Using Eclipse
  • Code Style Guidelines
  • FAQs

Initializing a Build Environment

The "Getting Started" section describes how to set up your local work environment, how to use Repo to get the Android files, and how to build the files on your machine. To build the Android source files, you will need to use Linux or Mac OS. Building under Windows is not currently supported.

Note: The source is approximately 2.6GB in size. You will need 10GB free to complete the build.

For an overview of the entire code-review and code-update process, see Life of a Patch.

To see snapshots and histories of the files available in the public Android repositories, visit theGitWeb web interface.

Setting up a Linux build environment

The Android build is routinely tested in house on recent versions of Ubuntu (10.04 and later), but most distributions should have the required build tools available. Reports of successes or failures on other distributions are welcome.

Note: It is also possible to build Android in a virtual machine. If you are running Linux in a virtual machine, you will need at least 8GB of RAM/swap and 12GB or more of disk space in order to build the Android tree.

In general you will need:

  • Python 2.4 -- 2.7, which you can download frompython.org.

  • JDK 6 if you wish to build Gingerbread or newer; JDK 5 for Froyo or older. You can download both fromjava.sun.com.

  • Git 1.5.4 or newer. You can find it atgit-scm.com.

  • (optional) Valgrind, a tool that will help you find memory leaks, stack corruption, array bounds overflows, etc. Download fromvalgrind.org.

Detailed instructions for Ubuntu 10.04+ follow.

Installing the JDK

The Sun JDK is no longer in Ubuntu's main package repository. In order to download it, you need to add the appropriate repository and indicate to the system which JDK should be used.

Java 6: for Gingerbread and newer

[forlong401 comments below lines-------------start---------]
[Please check your ubuntu version, maybe you needn't below two lines(add apt repository)]
[forlong401 comments above lines---------------end-------]
$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo add-apt-repository "deb-src http://archive.canonical.com/ubuntu lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk

Java 5: for Froyo and older

$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hardy main multiverse"$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hardy-updates main multiverse"$ sudo apt-get update$ sudo apt-get install sun-java5-jdk

Installing required packages

To set up your development environment, install the following required packages:

$ 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 [forlong401 comments below lines----------start------------] forlong401@xxx:~$ 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 正在读取软件包列表... 完成 正在分析软件包的依赖关系树  正在读取状态信息... 完成  注意,选取 lib32z1-dev 而非 lib32z-dev build-essential 已经是最新的版本了。 git-core 已经是最新的版本了。 gnupg 已经是最新的版本了。 libc6-dev 已经是最新的版本了。 libgl1-mesa-dev 已经是最新的版本了。 libgl1-mesa-dev 被设置为手动安装。 libx11-dev 已经是最新的版本了。 libx11-dev 被设置为手动安装。 x11proto-core-dev 已经是最新的版本了。 x11proto-core-dev 被设置为手动安装。 zip 已经是最新的版本了。 zlib1g-dev 已经是最新的版本了。 zlib1g-dev 被设置为手动安装。 ia32-libs 已经是最新的版本了。 curl 已经是最新的版本了。 libxml2-utils 已经是最新的版本了。 将会安装下列额外的软件包:  g++-4.5-multilib gcc-4.5-multilib gcc-multilib lib32gomp1 lib32readline5 libc6-dev-i386 libncurses5-dev m4 mingw32-binutils mingw32-runtime 建议安装的软件包:  bison-doc lib32stdc++6-4.5-dbg lib32mudflap0 ncurses-doc gcc-doc cpp-doc 下列【新】软件包将被安装:  bison flex g++-4.5-multilib g++-multilib gcc-4.5-multilib gcc-multilib gperf lib32gomp1 lib32ncurses5-dev lib32readline5 lib32readline5-dev lib32z1-dev libc6-dev-i386 libncurses5-dev m4 mingw32 mingw32-binutils mingw32-runtime  python-markdown tofrodos 升级了 0 个软件包,新安装了 20 个软件包,要卸载 0 个软件包,有 3 个软件包未被升级。 
[forlong401 comments above lines----------------------]

Configuring USB Access

Under GNU/linux systems (and specifically under Ubuntu systems),regular users can't directly access USB devices by default. Thesystem needs to be configured to allow such access.

The recommended approach is to create a file/etc/udev/rules.d/51-android.rules (as the root user) and to copythe following lines in it. must be replaced by theactual username of the user who is authorized to access the phonesover USB.

# adb protocol on passion (Nexus One) SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="<username>" # fastboot protocol on passion (Nexus One) SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="<username>" # adb protocol on crespo (Nexus S) SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="<username>" # fastboot protocol on crespo (Nexus S) SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="<username>" 

Those new rules take effect the next time a device is plugged in.It might therefore be necessary to unplug the device and plug itback into the computer.

This is known to work on both Ubuntu Hardy Heron (8.04.x LTS) andLucid Lynx (10.04.x LTS). Other versions of Ubuntu or othervariants of GNU/linux might require different configurations.

Setting up a Mac OS X build environment

To build the Android files in a Mac OS environment, you need an Intel/x86 machine running MacOS 10.4 (Tiger), 10.5 (Leopard), or 10.6 (Snow Leopard). The Android build system and tools do not support the obsolete PowerPC architecture.

Android must be built on a case-sensitive file system because the sources contain files that differ only in case. We recommend that you build Android on a partition that has been formatted with the journaled file system HFS+. HFS+ is required to successfully build Mac OS applications such as the Android Emulator for OS X.

Creating a case sensitive disk image

If you want to avoid partitioning/formatting your hard drive, you can usea case-sensitive disk image instead. To create the image, launch DiskUtility and select "New Image". A size of 12GB is the minimum tocomplete the build, larger numbers are more future-proof. Using sparse imagessaves space while allowing to grow later as the need arises. Be sure to select"case sensitive, journaled" as the volume format.

You can also create it from a shell with the following command:

# hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 40g ~/android.dmg

This will create a .dmg file which, once mounted, acts as a drive with the required formatting for Android development. For a disk image named "android.dmg" stored in your home directory, you can add the following to your~/.bash_profile to mount the image when you execute "mountAndroid":

# mount the android file imagefunction mountAndroid { hdiutil attach ~/android.dmg -mountpoint /Volumes/android; }

Once mounted, you'll do all your work in the "android" volume. You can eject it (unmount it) just like you would with an external drive.

Installing required packages

  • Install XCode from the Apple developer site. We recommend version 3.0 or newer. If you are not already registered as an Apple developer, you will have to create an Apple ID in order to download.

  • Install MacPorts from macports.org.

    Note: Make sure that /opt/local/bin appears in your path BEFORE/usr/bin. If not, add

    export PATH=/opt/local/bin:$PATH

    to your ~/.bash_profile.

  • Get make, git, and GPG packages from MacPorts:

    $ POSIXLY_CORRECT=1 sudo port install gmake libsdl git-core gnupg

    If using Mac OS 10.4, also install bison:

    $ POSIXLY_CORRECT=1 sudo port install bison

Reverting from make 3.82

There is a bug in gmake 3.82 that prevents android from building. You can install version 3.81 using MacPorts by taking the following steps:

  • Edit /opt/local/etc/macports/sources.conf and add a line that says

    file:///Users/Shared/dports

    above the rsync line. Then create this directory:

    $ mkdir /Users/Shared/dports
  • In the new dports directory, run

    $ svn co --revision 50980 http://svn.macports.org/repository/macports/trunk/dports/devel/gmake/ devel/gmake/
  • Create a port index for your new local repository:

    $ portindex /Users/Shared/dports
  • Finally, install the old version of gmake with

    $ sudo port install gmake @3.81

Setting a file descriptor limit

On MacOS the default limit on the number of simultaneous file descriptors open is too low and a highly parallel build process may exceed this limit.

To increase the cap, add the following lines to your ~/.bash_profile:

# set the number of open files to be 1024ulimit -S -n 1024

Next: Download the source

Your build environment is good to go! Proceed to downloading the source....


Origin Link: http://source.android.com/source/initializing.html

Caution Red Color Key Words.


更多相关文章

  1. Android各个版本 版本号对应关系表
  2. 在 Android(安卓)11 及更高版本系统中处理可空性
  3. 5张图片解决android studio报错:Failed to resolve: com.android.
  4. Android:Android(安卓)6.0+权限适配--简单粗暴
  5. {Android} 测试Google Play In-App-Billing支付
  6. 设计应用Logo Android(安卓)- Asset Studio Integration
  7. 使用VS2015调试Android的C++动态链接库
  8. Kivy A to Z -- 如何从python代码中直接访问Android的Service
  9. Android(安卓)开发经验汇总

随机推荐

  1. Android(安卓)HAL模块实现
  2. 从Android项目学习Kotlin(一)
  3. android的binder机制研究(C++部分)
  4. android控件属性介绍
  5. Android中的SurfaceView详解
  6. 《阿里巴巴Android开发手册》正式发布,安
  7. 第1步:搭建Android的开发环境(从零开始学An
  8. 关于Android(安卓)2.2与2.3 adb.exe版本
  9. Android(安卓)内存泄漏调试
  10. Android中Input型输入设备驱动原理分析(