Ubuntu10.04 下载Android2.3.3源码笔记

时间:2023-02-08 20:45:37

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 from python.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 at git-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

$ 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 dapper main multiverse"



$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu dapper-updates main multiverse"



$ sudo apt-get update



$ sudo apt-get install sun-java5-jdk







改变设置的jdk设置有两种方法:



1在.bashrc中添加, android 2.3.4使用的是jdk6



#check the window size after each command and, if necessary,



20 export JAVA_HOME="/usr/lib/jvm/java-1.5.0-sun"



21 export JRE_HOME="/usr/lib/jvm/java-1.5.0-sun/jre"



22 #export JAVA_HOME="/usr/lib/jvm/java-6-sun"



23 #export JRE_HOME="/usr/lib/jvm/java-6-sun/jre"



24 export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH



25 export PATH=$PATH:"$JAVA_HOME/bin:$JRE_HOME/bin"



26 export PATH=$PATH:"/home/b576/Downloads/android-sdk-linux_x86-1.6_r1/tools/ "



27 export PATH=$PATH:"/home/b576/Downloads/android-sdk-linux_x86-1.6_r1/platform-tools"







OR







sudo update-alternatives --config java



Installing required packages

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

64-bit systems:

$ 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



32-bit systems:

$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev







libncurses5-dev x11proto-core-dev libx11-dev libreadline5-dev libz-dev libgl1-mesa-dev



For building Froyo or an older release on a 64-bit system, several other packages are necessary to establish a 32-bit build environment:

$ sudo apt-get install gcc-multilib g++-multilib libc6-i386 libc6-dev-i386



以上这些是官网上列出的所需的软件包,但是后面有几个软件包apt-get install 的时候会说找不到软件包。网上遍历资料后,在csdn的一个哥们的提问得到帮助。

sudo apt-get install -y git-core gnupg flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev

Downloading the Source Tree

Installing Repo

Repo is a tool that makes it easier to work with Git in the context of Android. For more information about Repo, seeVersion Control.

To install, initialize, and configure Repo, follow these steps:

  • 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 script and ensure it is executable:

    $ curl http://android.git.kernel.org/repo > ~/bin/repo



    $ chmod a+x ~/bin/repo



Initializing a Repo client

After installing Repo, set up your client to access the android source repository:

  • Create an empty directory to hold your working files:

    $ mkdir WORKING_DIRECTORY



    $ cd WORKING_DIRECTORY



  • 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 git://android.git.kernel.org/platform/manifest.git



    To check out a branch other than "master", specify it with -b:

    $ repo init -u git://android.git.kernel.org/platform/manifest.git -b gingerbread



  • When prompted, please configure Repo with your real name and email address. To use the Gerrit code-review tool, you will need an email address that is connected with aregistered Google account. Make sure this is a live address at which you can receive messages. The name that you provide here will show up in attributions for your code submissions.

A successful initialization will end with a message stating that Repo is initialized in your working directory. Your client directory should now contain a.repo directory where files such as the manifest will be kept.

Getting the files

To pull down files to your working directory from the repositories as specified in the default manifest, run

$ repo sync

The Android source files will be located in your working directory under their project names. The initial sync operation will take several minutes to complete. For more aboutrepo sync and other Repo commands, see Version Control.

Verifying Git Tags

Load the following public key into your GnuPG key database. The key is used to sign annotated tags that represent releases.

$ gpg --import

Copy and paste the key(s) below, then enter EOF (Ctrl-D) to end the input and process the keys.

-----BEGIN PGP PUBLIC KEY BLOCK-----Version: GnuPG v1.4.2.2 (GNU/Linux)mQGiBEnnWD4RBACt9/h4v9xnnGDou13y3dvOx6/t43LPPIxeJ8eX9WB+8LLuROSVlFhpHawsVAcFlmi7f7jdSRF+OvtZL9ShPKdLfwBJMNkU66/TZmPewS4m782ndtw78tR1cXb197Ob8kOfQB3A9yk2XZ4ei4ZC3i6wVdqHLRxABdncwu5hOF9KXwCgkxMDu4PVgChaAJzTYJ1EG+UYBIUEAJmfearb0qRAN7dEoff0FeXsEaUA6U90sEoVks0ZwNj96SA8BL+a1OoEUUfpMhiHyLuQSftxisJxTh+2QclzDviDyaTrkANjdYY7p2cq/HMdOY7LJlHaqtXmZxXjjtw5Uc2QG8UY8aziU3IE9nTjSwCXeJnuyvoizl9/I1S5jU5SA/9WwIps4SC84ielIXiGWEqq6i6/sk4I9q1YemZF2XVVKnmI1F4iCMtNKsR4MGSa1gA8s4iQbsKNWPgp7M3a51JCVCu6l/8zTpA+uUGap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+jv2QSTlrx4KLM==Wi5D-----END
PGP PUBLIC KEY BLOCK-----

 

After importing the keys, you can verify any tag with

$ git tag -v TAG_NAME

 

Building the System

The basic sequence of build commands is as follows:

Initialize

Initialize the environment with the envsetup.sh script. Notethat 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 asan argument, e.g.

$ lunch full-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 codenamereferring to the particular feature combination:

Build name Device Notes
generic emulator lowest-common denominator
full emulator fully configured with all languages, apps, input methods
full_crespo crespo full build running on Nexus S ("crespo")

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, seeBuilding for devices

Build the Code

Build everything with make. GNU make can handle paralleltasks with a-jN argument, and it's common to use a number oftasks N that's between 1 and 2 times the number of hardwarethreads on the computer being used for the build. E.g. on adual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core),the fastest builds are made with commands between make -j16 andmake -j32.

$ make -j4



Run It!

You can either run your build on an emulator or flash it on a device. Please note that you have already selected your build target withlunch, and it is unlikely at best to run on a different target than it was built for.

 

 

 

如果在make的时候会提示出错:

************************************************************

You are attempting to build on a 32-bit system.

Only 64-bit build environments are supported beyond froyo/2.2.

************************************************************

因为Android2.3默认是64位的系统上编译,需要手动修改build/core/main.mk,把这个判断部分注释掉:

#ifneq (64,$(findstring 64,$(build_arch)))

#$(warning ************************************************************)

#$(warning You are attempting to build on a 32-bit system.)

#$(warning Only 64-bit build environments are supported beyond froyo/2.2.)

#$(warning ************************************************************)

#$(error stop)

#endif

OR

然后,将
./build/core/main.mk 中的
ifneq (64,$(findstring 64,$(build_arch)))
改为:
ifneq (i686,$(findstring i686,$(build_arch)))

重新make,如果是安装了JDK6版本,会又报错:

Docs droiddoc: out/target/common/docs/api-stubs

Could not load ‘clearsilver-jni’

java.library.path = out/host/linux-x86/lib

make: *** [out/target/common/docs/api-stubs-timestamp] Error 45

make: *** Waiting for unfinished jobs….

Could not load ‘clearsilver-jni’

java.library.path = out/host/linux-x86/lib然后,将
./build/core/main.mk 中的
ifneq (64,$(findstring 64,$(build_arch)))
改为:
ifneq (i686,$(findstring i686,$(build_arch)))

make: *** [out/target/common/docs/doc-comment-check-timestamp] Error 45

这是由于clearsilver在编译时如果检测到使用Java JDK 6,就使用64位编译,因为Google的一个员工更新了几个文件。这里可以看到详细的修改记录:http://android.git.kernel.org/?p=platform/external/clearsilver.git;a=commitdiff;h=d36910a8110d8377b22301274d2b5131a732a72b

修改这几个文件,该回到32位编译环境即可:

external/clearsilver/cgi/Android.mk

external/clearsilver/java-jni/Android.mk

external/clearsilver/util/Android.mk

external/clearsilver/cs/Android.mk

把编译选项-m64改成-m32即可

在externel/clearsilver/make clean一下。

重新make,大概不到一个小时就make完了。

要解决gnu/stubs-64.h: No such file or directory,需:
apt-get install libc6-dev-amd64

要解决/usr/bin/ld: cannot find -lstdc++,需:
apt-get install g++-multilib lib64stdc++6 

要解决/usr/bin/ld: cannot find -lz,需
apt-get install lib64z1-dev