现在的位置: 首页 > 综合 > 正文

【指导]如何编译完整建立开发环境和编译Android 4.0.1 on Ubuntu 11.04 (64 bit)

2013年02月05日 ⁄ 综合 ⁄ 共 7962字 ⁄ 字号 评论关闭
文章目录

 建议大家直接飞官方这里下载:

传送门:      http://source.android.com/source/downloading.html

As promised my how-to for building Android 2.3.4 on Ubuntu 11.04 (64 bit). I found out that building Android changed a bit since Ubuntu 11.04 and the documentation on the Android source site isn’t up to date. This is why i choose to write down the steps
i did to build Android 2.3.4. So, go grab yourself a Red Bull and let’s get ready to rumble!

What do you need?

Ubuntu 11.04 (64 bit), a internet connection & if your building for a phone.. The phone.

Preparing Ubuntu:准备下载源

Fire up a terminal, and download the following packages to start with:

sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev g++-multilib lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev libgl1-mesa-dev

Now make sure your using the right version of Java:

sudo add-apt-repository "deb http://archive.canonical.com/ natty partner"
sudo add-apt-repository "deb-src http://archive.canonical.com/ubuntu natty partner"
sudo apt-get update
sudo apt-get install sun-java6-jdk

You just downloaded all the software needed to build Android.

Make sure that your Ubuntu machine can use your USB devices by creating /etc/udev/rules.d/51-android.rules (as root user) paste the following inside that file:

# 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>"

Please make sure to switch “<username>” to the username of your Ubuntu user.

Now it’s time to download the repo and stuff like that. In the same terminal type:

mkdir ~/bin
curl http://android.git.kernel.org/repo > ~/bin/repo
sudo chmod +x ~/bin/repo

Now open up your bashrc (nano ~/.bashrc) and add the following to the end:

PATH=$PATH:$HOME/bin

Save the file and source it:

source ~/.bashrc

Getting the source: 获取源码 因为源码服务器现在由谷歌提供,所以地址已经更换。

1月6日:更新下载地址,看这篇文章的朋友请注意下载地址已经是最新的了。

 

  • $ mkdir ~/bin
    $ PATH=~/bin:$PATH
    
  • Download the Repo script and ensure it is executable:

    $ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
    $ chmod a+x ~/bin/repo
    
  • The SHA-1 checksum for repo is 29ba4221d4fccdfa8d87931cd73466fdc24040b5

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. 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 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
    

    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
    
  • 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 directoryunder their project names. The initial sync operation will takean hour or more to complete. For more aboutrepo sync and otherRepo commands, seeVersion
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 PUBLI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zKMX
LWBGWE0znfRrnczI5p49i2YZJAjyX1P2WzmScK49CV82dzLo71MnrF6fj+Udtb5+
OgTg7Cow+8PRaTkJEW5Y2JIZpnRUq0CYxAmHYX79EMKHDSThf/8AAwUIAJPWsB/M
pK+KMs/s3r6nJrnYLTfdZhtmQXimpoDMJg1zxmL8UfNUKiQZ6esoAWtDgpqt7Y7s
KZ8laHRARonte394hidZzM5nb6hQvpPjt2OlPRsyqVxw4c/KsjADtAuKW9/d8phb
N8bTyOJo856qg4oOEzKG9eeF7oaZTYBy33BTL0408sEBxiMior6b8LrZrAhkqDjA
vUXRwm/fFKgpsOysxC6xi553CxBUCH2omNV6Ka1LNMwzSp9ILz8jEGqmUtkBszwo
G1S8fXgE0Lq3cdDM/GJ4QXP/p6LiwNF99faDMTV3+2SAOGvytOX6KjKVzKOSsfJQ
hN0DlsIw8hqJc0WISQQYEQIACQUCSedYRAIbDAAKCRDorT+BmrEOeCUOAJ9qmR0l
EXzeoxcdoafxqf6gZlJZlACgkWF7wi2YLW3Oa+jv2QSTlrx4KLM=
=Wi5D
-----END PGP PUBLIC KEY BLOCK-----

After importing the keys, you can verify any tag with

$ git tag -v TAG_NAME

If you haven't
set up ccache
yet,now would be a good time to do it.

Downloading kernels

If you are only interested in kernel sources,you can get the kernel you are interested in through one of the followingcommands:

下面是几个厂商的内核,msm,omap ,samsung 等。

$ git clone https://android.googlesource.com/kernel/common.git
$ git clone https://android.googlesource.com/kernel/goldfish.git
$ git clone https://android.googlesource.com/kernel/msm.git 
$ git clone https://android.googlesource.com/kernel/omap.git
$ git clone https://android.googlesource.com/kernel/samsung.git
$ git clone https://android.googlesource.com/kernel/tegra.git

Building the source: 编译源码

First i will explain how to build a normal generic build. This is a non phone specific build. In the Android source folder type:

. build/envsetup.sh  让环境生效 执行source build/envsetup.sh 也可以。

This will prepare your build environment. This is needed to have tools like lunch, mmm and other nifty Android specific tools. Now it’s time to actually choose our version of 2.3.4:

lunch 

You will be asked which Android version you want, choose “generic”. Now! It’s time for the real deal, building the source. It’s time to fire up make:

make -j4  多线程编译

Do note that there are diffrent -j parameters of make to build faster. You could use make -j4 if you have 2 cores, and make -j8 if you have 4. This will speed up the building.

If the building ends with something like system.img that the build went ok. Congratulations you’ve just build Android 2.3.4. You can flash it to your phone with fastboot. But this is just a generic build missing device specific features.

Building the source for the Nexus One:

Connect your phone to your PC, and make sure that it’s on debugging mode. From the root of your source, go to the Passion (code name for Nexus One) specific folder:

cd device/htc/passion

Import all the needed files:

./extract-files.sh

If this ends with no errors your done, you can now return to the root of your source tree. If you followed this how to go back to:

~/Android/source/Gingerbread

Now use lunch to choose the passion-full-userdebug build.

lunch

And! Now you can use make to build Android:

make -j4

If your build ends with something like this:

Install system fs image: out/target/product/passion/system.img

The build is complete. You can again use fastboot to flash it to your device. You now have the full open source version of Android running on your phone.

If you have any questions about this topic please don’t hesitate to ask them in the comments i’ll do my best to give answers when possible.

抱歉!评论已关闭.