http://blog.csdn.net/hens007/article/details/7428691
官網(wǎng)內(nèi)容:
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 download is approximately 6GB in size. You will need 25GB free to complete a single build, and up to 80GB (or more) for a full set of builds.
For an overview of the entire code-review and code-update process, see Life of a Patch.
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. 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 16GB of RAM/swap and 30GB 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 from java.sun.com.
Git 1.7 or newer. You can find it at git-scm.com.
Detailed instructions for Ubuntu 10.04+ follow.
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 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
64-bit (recommended)
$ 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
On newer versions of Ubuntu such as 11.10 you may need to do the following:
$ sudo ln -s /usr/lib/i386-linux-gnu/libX11.so.6 /usr/lib/i386-linux-gnu/libX11.so
32-bit (experimental)
$ 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 libreadline6-dev libgl1-mesa-dev tofrodos python-markdown libxml2-utils
Under GNU/linux systems (and specifically under Ubuntu systems), regular users can't directly access USB devices by default. The system 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 copy the following lines in it.must be replaced by the actual username of the user who is authorized to access the phones over 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/crespo4g (Nexus S)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="<username>"# fastboot protocol on crespo/crespo4g (Nexus S)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="<username>"# adb protocol on maguro (Galaxy Nexus)SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="<username>"# fastboot protocol on maguro (Galaxy Nexus)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", 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 it back into the computer.
This is known to work on both Ubuntu Hardy Heron (8.04.x LTS) and Lucid Lynx (10.04.x LTS). Other versions of Ubuntu or other variants of GNU/linux might require different configurations.
To build the Android files in a Mac OS environment, you need an Intel/x86 machine running MacOS 10.6 (Snow Leopard).
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.
If you want to avoid partitioning/formatting your hard drive, you can use a case-sensitive disk image instead. To create the image, launch Disk Utility and select "New Image". A size of 25GB is the minimum to complete the build, larger numbers are more future-proof. Using sparse images saves 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 (or possibly a .dmg.sparsefile) 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.
Install XCode from the Apple developer site. We recommend version 3.1.4 or newer, i.e. gcc 4.2. Version 4.x could cause difficulties. 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
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
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
Repo is a tool that makes it easier to work with Git in the context of Android. For more information about Repo, see Version 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 https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo$ chmod a+x ~/bin/repo
The SHA-1 checksum for repo is e1fd3bef059d152edf4d0522590725d317bc637f
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 a registered 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.
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 an hour or more to complete. For more about repo sync
and other Repo commands, see Version Control.
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+uUGapw4tWCp4o0dpIvDPBEa9b/aF/ygcR8mh5hgUfpF9IpXdknOsbKCvM9lSSfRciETykZc4wrRCVGhlIEFuZHJvaWQgT3BlbiBTb3VyY2UgUHJvamVjdCA8aW5pdGlhbC1jb250cmlidXRpb25AYW5kcm9pZC5jb20+iGAEExECACAFAknnWD4CGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAAKCRDorT+BmrEOeNr+AJ42Xy6tEW7r3KzrJxnRX8mij9z8tgCdFfQYiHpYngkI2t09Ed+9Bm4gmEO5Ag0ESedYRBAIAKVW1JcMBWvV/0Bo9WiByJ9WJ5swMN36/vAlQN4mWRhfzDOk/Rosdb0csAO/l8Kz0gKQPOfObtyYjvI8JMC3rmi+LIvSUT9806UphisyEmmHv6U8gUb/xHLIanXGxwhYzjgeuAXVCsv+EvoPIHbY4L/KvP5x+oCJIDbkC2b1TvVk9PryzmE4BPIQL/NtgR1oLWm/uWR9zRUFtBnE411aMAN3qnAHBBMZzKMXLWBGWE0znfRrnczI5p49i2YZJAjyX1P2WzmScK49CV82dzLo71MnrF6fj+Udtb5+OgTg7Cow+8PRaTkJEW5Y2JIZpnRUq0CYxAmHYX79EMKHDSThf/8AAwUIAJPWsB/MpK+KMs/s3r6nJrnYLTfdZhtmQXimpoDMJg1zxmL8UfNUKiQZ6esoAWtDgpqt7Y7sKZ8laHRARonte394hidZzM5nb6hQvpPjt2OlPRsyqVxw4c/KsjADtAuKW9/d8phbN8bTyOJo856qg4oOEzKG9eeF7oaZTYBy33BTL0408sEBxiMior6b8LrZrAhkqDjAvUXRwm/fFKgpsOysxC6xi553CxBUCH2omNV6Ka1LNMwzSp9ILz8jEGqmUtkBszwoG1S8fXgE0Lq3cdDM/GJ4QXP/p6LiwNF99faDMTV3+2SAOGvytOX6KjKVzKOSsfJQhN0DlsIw8hqJc0WISQQYEQIACQUCSedYRAIbDAAKCRDorT+BmrEOeCUOAJ9qmR0lEXzeoxcdoafxqf6gZlJZlACgkWF7wi2YLW3Oa+jv2QSTlrx4KLM==Wi5D-----END PGP PUBLIC KEY BLOCK-----
After importing the keys, you can verify any tag with
$ git tag -v TAG_NAME
The basic sequence of build commands is as follows:
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 which target to build with lunch
. The exact configuration can be passed as an 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 codename referring to the particular feature combination:
Build name | Device | Notes |
---|---|---|
full | emulator | fully configured with all languages, apps, input methods |
full_maguro | maguro | full build running on Galaxy Nexus GSM/HSPA+ ("maguro") |
full_panda | panda | full build 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 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
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 with lunch
, and it is unlikely at best to run on a different target than it was built for.
To flash a device, you will need to use fastboot
, which should be included in your path after a successful build. Place the device in fastboot mode either manually by holding the appropriate key combination at boot, or from the shell with
$ adb reboot bootloader
Once the device is in fastboot mode, run
$ fastboot flashall -w
The -w
option wipes the /data
partition on the device; this is useful for your first time flashing a particular device, but is otherwise unnecessary.
For more information about building for and running on actual hardware, see Building for devices
The emulator is added to your path automatically by the build process. To run the emulator, type
$ emulator
ccache is a compiler cache for C and C++ that can help make builds faster. In the root of the source tree, do the following:
$ export USE_CCACHE=1$ export CCACHE_DIR=/<path_of_your_choice>/.ccache$ prebuilt/linux-x86/ccache/ccache -M 20G
You can watch ccache being used by doing the following:
$ watch -n1 -d prebuilt/linux-x86/ccache/ccache -s
On OSX, you should replace linux-x86
with darwin-x86
.
If you are attempting to build froyo or earlier with Java 1.6, or gingerbread or later with Java 1.5, make
will abort with a message such as
************************************************************You are attempting to build with the incorrect versionof java.Your version is: WRONG_VERSION.The correct version is: RIGHT_VERSION.Please follow the machine setup instructions at http://source.android.com/download************************************************************
This may be caused by
failing to install the correct JDK as specified on the Initializing page. Building Android requires Sun JDK 5 or 6 depending on which release you are building.
another JDK that you previously installed appearing in your path. You can remove the offending JDK from your path with:
$ export PATH=${PATH/\/path\/to\/jdk\/dir:/}
Repo is built on particular functionality from Python 2.x and is unfortunately incompatible with Python 3. In order to use repo, please install Python 2.x:
$ apt-get install python
There is a bug in make
version 3.82 on Mac OS that prevents building Android.
TODO: what the error looks like with GNU make 3.82 on older builds that don't explicitly detect it.
Follow the instructions on the Initializing page for reverting GNU make from 3.82 to 3.81.
If you are building on an HFS filesystem on Mac OS X, you may encounter an error such as
************************************************************You are building on a case-insensitive filesystem.Please move your source tree to a case-sensitive filesystem.************************************************************
Please follow the instructions on the Initializing page for creating a case-sensitive disk image.
On most Linux systems, unprivileged users cannot access USB ports by default. If you see a permission denied error, follow the instructions on the Initializing page for configuring USB access.
If adb was already running and cannot connect to the device after getting those rules set up, it can be killed with adb kill-server
. That will cause adb to restart with the new configuration.
This page complements the main page about Building with information that is specific to individual devices.
The only supported phone with the current release is the GSM/HSPA+ Galaxy Nexus, a.k.a. "maguro". GSM/HSPA+ Galaxy Nexus is currently the recommended device to use with the Android Open-Source Project.
In addition, PandaBoard a.k.a. "panda" is supported in the master branch only, but is currently considered experimental. The specific details to use a PandaBoard with the Android Open-Source Project are in the file device/ti/panda/README
in the source tree.
Nexus S, a.k.a. "crespo", and Nexus S 4G, a.k.a. "crespo4g", are supported with gingerbread, but can't currently be used with newer versions of the Android Open-Source Project.
Nexus One a.k.a. "passion" is obsolete, was experimental in gingerbread and unsupported, and can't be used with newer versions of the Android Open-Source Project.
Android Developer Phones (ADP1 and ADP2, a.k.a. "dream" and "sapphire") are obsolete, were experimental and unsupported in froyo, and can't be used with newer versions of the Android Open-Source Project.
If you don't already have those tools, fastboot and adb can be built with the regular build system. Follow the instructions on the page about building, and replace the main make
command with
$ make fastboot adb
During a cold boot, the following key combinations can be used to boot into fastboot mode, which is a mode in the bootloader that can be used to flash the devices:
Device | Keys |
---|---|
maguro | Press and hold both Volume Up and Volume Down, then press and hold Power |
crespo | Press and hold Volume Up, then press and hold Power |
crespo4g | Press and hold Volume Up, then press and hold Power |
passion | Press and hold the trackball, then press Power |
sapphire | Press and hold Back, then press Power |
dream | Press and hold Back, then press Power |
Also, on devices running froyo or later where adb is enabled, the command adb reboot bootloader
can be used to reboot from Android directly into the bootloader with no key combinations.
It's only possible to flash a custom system if the bootloader allows it.
This is the default setup on ADP1 and ADP2.
On Nexus One, Nexus S, Nexus S 4G, and Galaxy Nexus, the bootloader is locked by default. With the device in fastboot mode, the bootloader is unlocked with
$ fastboot oem unlock
The procedure must be confirmed on-screen, and deletes the user data for privacy reasons. It only needs to be run once.
On Nexus One, the operation voids the warranty and is irreversible.
On Nexus S, Nexus S 4G, and Galaxy Nexus, the bootloader can be locked back with
$ fastboot oem lock
Starting with IceCreamSandwich, the Android Open-Source Project can't be used from pure source code only, and requires additional hardware-related proprietary libraries to run, specifically for hardware graphics acceleration.
Official binaries for Nexus S, Nexus S 4G, Galaxy Nexus, and PandaBoard can be downloaded from Google's Nexus driver page, which add access to additional hardware capabilities with non-Open-Source code.
There are no official binaries for Nexus One, ADP2 or ADP1.
Each set of binaries comes as a self-extracting script in a compressed archive. After uncompressing each archive, run the included self-extracting script from the root of the source tree, confirm that you agree to the terms of the enclosed license agreement, and the binaries and their matching makefiles will get installed in the vendor/
hierarchy of the source tree.
There's an additional step on Nexus S 4G. Build the signapk tool with
$ make signapk
Then reassemble the proprietary applicatons with
$ vendor/samsung/crespo4g/reassemble-apks.sh
In order to make sure that the newly installed binaries are properly taken into account after being extracted, the existing output of any previous build needs to be deleted with
$ make clobber
The steps to configure and build the Android Open-Source Project are described in the page about Building.
The recommended builds for the various devices are available through the lunch menu, accessed when running the lunch
command with no arguments:
Device | Branch | Build configuration |
---|---|---|
maguro | android-4.0.1_r1 | full_maguro-userdebug |
panda | master | full_panda-eng |
crespo | android-2.3.6_r1 | full_crespo-userdebug |
crespo4g | android-2.3.7_r1 | full_crespo4g-userdebug |
passion | android-2.3.6_r1 | full_passion-userdebug |
sapphire | android-2.2.2_r1 | full_sapphire-userdebug |
dream | android-2.2.2_r1 | full_dream-userdebug |
Set the device in fastboot mode if necessary (see above).
Because user data is typically incompatible between builds of Android, it's typically better to delete it when flashing a new system.
$ fastboot erase cache$ fastboot erase userdata
An entire Android system can be flashed in a single command: this writes the boot, recovery and system partitions together after verifying that the system being flashed is compatible with the installed bootloader and radio, and reboots the system.
$ fastboot flashall
On maguro, panda, crespo, crespo4g, sapphire and dream (but not on passion), the commands above can be replaced with a single command
$ fastboot -w flashall
On Nexus S, Nexus S 4G, and Galaxy Nexus, each version of Android has only been thoroughly tested with on specific version of the underlying bootloader and cell radio software. However, no compatibility issues are expected when running newer systems with older bootloaders and radio images according to the following tables.
Nexus S (worldwide version "XX"):
Android Version | Preferred Bootloader | Preferred Radio | Also possible |
---|---|---|---|
2.3 (GRH55) | I9020XXJK1 | I9020XXJK8 | |
2.3.1 (GRH78) | I9020XXJK1 | I9020XXJK8 | |
2.3.2 (GRH78C) | I9020XXJK1 | I9020XXJK8 | |
2.3.3 (GRI40) | I9020XXKA3 | I9020XXKB1 | All previous versions |
2.3.4 (GRJ22) | I9020XXKA3 | I9020XXKD1 | All previous versions |
2.3.5 (GRJ90) | I9020XXKA3 | I9020XXKF1 | All previous versions |
2.3.6 (GRK39F) | I9020XXKA3 | I9020XXKF1 | All previous versions |
Nexus S (850MHz version "UC"):
Android Version | Preferred Bootloader | Preferred Radio | Also possible |
---|---|---|---|
2.3.3 (GRI54) | I9020XXKA3 | I9020UCKB2 | |
2.3.4 (GRJ22) | I9020XXKA3 | I9020UCKD1 | All previous versions |
2.3.5 (GRJ90) | I9020XXKA3 | I9020UCKF1 | All previous versions |
2.3.6 (GRK39C) | I9020XXKA3 | I9020UCKF1 | All previous versions |
2.3.6 (GRK39F) | I9020XXKA3 | I9020UCKF1 | All previous versions |
Nexus S (Korea version "KR"):
Android Version | Preferred Bootloader | Preferred Radio | Also possible |
---|---|---|---|
2.3.3 (GRI54) | I9020XXKA3 | I9020KRKB3 | |
2.3.4 (GRJ22) | I9020XXKA3 | M200KRKC1 | All previous versions |
2.3.5 (GRJ90) | I9020XXKA3 | M200KRKC1 | All previous versions |
2.3.6 (GRK39F) | I9020XXKA3 | M200KRKC1 | All previous versions |
Nexus S 4G:
Android Version | Preferred Bootloader | Preferred Radio | Also possible |
---|---|---|---|
2.3.4 (GRJ06D) | D720SPRKC5 | D720SPRKC9 | |
2.3.4 (GRJ22) | D720SPRKC5 | D720SPRKD8 | All previous versions |
2.3.5 (GRJ90) | D720SPRKC5 | D720SPRKE5 | All previous versions |
2.3.7 (GWK74) | D720SPRKE1 | D720SPRKH1 (*) | All previous versions |
Galaxy Nexus (GSM/HSPA+):
Android Version | Preferred Bootloader | Preferred Radio | Also possible |
---|---|---|---|
4.0.1 (ITL41D) | PRIMEKJ10 | I9250XXKK1 |
If you're building a new version of Android, if your Nexus S, Nexus S 4G or Galaxy Nexus has an older bootloader and radio image that is marked as being also possible in the table above but is not recognized by fastboot, you can locally delete the version-bootloader
and version-baseband
lines in device/samsung/crespo/board-info.txt
or device/samsung/crespo4g/board-info.txt
ordevice/samsung/maguro/board-info.txt
(*) As a note, radio version D720SPRKH1 for Nexus S 4G sometimes erroneously reports version D720SPRKE1. If this is the case for your Nexus S 4G, you can locally modify the version-baseband line in device/samsung/crespo4g/board-info.txt
accordingly.
一. 環(huán)境準(zhǔn)備。
1.安裝git
sudo apt-get install git-core
2.安裝curl
sudo apt-get install git-core curl
3.安裝repo, 通過(guò)curl下載repo
curl http://git-repo.googlecode.com/files/repo-1.12 > ~/bin/repo
4.給repo可執(zhí)行權(quán)限
chmod a+x ~/bin/repo
5.修改~/bin/repo文件將第五行
REPO_URL='https://code.google.com/p/git-repo/'
改為
REPO_URL='http://code.google.com/p/git-repo/'
否則會(huì)出現(xiàn)error:Failed connect to code.google.com:443; Operation now in progress while accessing https://code.google.com/p/git-repo//info/refs
6.然后向PATH中添加bin路徑:
export PATH=$PATH:~/bin
7.新建一個(gè)目錄,然后進(jìn)入該目錄。
mkdir myAndroid
cd myAndroid
8.初始化版本庫(kù)
執(zhí)行repo init -u git://Android.git.linaro.org/platform/manifest.git -b android-2.3.4_r1
這一步大概有一分多鐘就完成了。
9.找到myAndroid目錄中的.repo下面的manifest.xml文件,該文件只是一個(gè)鏈接,實(shí)際上是manifest目錄下面的default.xml文件,將
fetch="git://Android.git.kernel.org/"
改為
fetch="git://Android.git.linaro.org/"
10.執(zhí)行repo sync
開始正式編譯,在源碼目錄下make即可。
make
我完全不知道跑了個(gè)啥,只知道超級(jí)卡。完成后產(chǎn)生的out文件夾有3.9G。
鏡像生成在out/target/product/generic下:android源碼編譯后得到system.img,ramdisk.img,userdata.img映像文件。其中, ramdisk.img是emulator的文件系統(tǒng),system.img包括了主要的包、庫(kù)等文件,userdata.img包括了一些用戶數(shù)據(jù),emulator加載這3個(gè)映像文件后,會(huì)把 system和 userdata分別加載到 ramdisk文件系統(tǒng)中的system和 userdata目錄下。
當(dāng)然編譯是件很痛苦的事情:
錯(cuò)誤1:
************************************************************
You are attempting to build on a 32-bit system.
Only 64-bit build environments are supported beyond froyo/2.2.
************************************************************
解決:
需要進(jìn)行如下修改即可,將
./external/clearsilver/cgi/Android.mk
./external/clearsilver/java-jni/Android.mk
./external/clearsilver/util/Android.mk
./external/clearsilver/cs/Android.mk
四個(gè)文件中的
LOCAL_CFLAGS += -m64
LOCAL_LDFLAGS += -m64
注釋掉,或者將“64”換成“32”
LOCAL_CFLAGS += -m32
LOCAL_LDFLAGS += -m32
然后,將./build/core/main.mk 中的
ifneq (64,$(findstring 64,$(build_arch)))
改為:
ifneq (i686,$(findstring i686,$(build_arch)))
錯(cuò)誤2:
host C++: libutils <= frameworks/base/libs/utils/RefBase.cpp
frameworks/base/libs/utils/RefBase.cpp: In member function ‘void android::RefBase::weakref_type::trackMe(bool, bool)’:
frameworks/base/libs/utils/RefBase.cpp:483:67: error: passing ‘const android::RefBase::weakref_impl’ as ‘this’ argument of ‘void android::RefBase::weakref_impl::trackMe(bool, bool)’ discards qualifiers [-fpermissive]
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o] 錯(cuò)誤 1
解決:
gedit frameworks/base/libs/utils/Android.mk
Change the line:
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)
To:
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) –fpermissive
host Executable: aapt (out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt)
out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_get':
/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:27: undefined reference to `pthread_getspecific'
out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_set':
/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:36: undefined reference to `pthread_key_create'
/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:44: undefined reference to `pthread_setspecific'
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt] 錯(cuò)誤 1
解決:
打開 frameworks/base/tools/aapt/Android.mk
ifeq ($(HOST_OS),linux)
#LOCAL_LDLIBS += -lrt 把這行注釋掉,改為下面一行。
LOCAL_LDLIBS += -lrt -lpthread
endif
錯(cuò)誤4:
target Dex: core
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# SIGSEGV (0xb) at pc=0x4003d848, pid=7668, tid=2889534320
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_22-b03 mixed mode)
# Problematic frame:
# C [libpthread.so.0+0xa848] pthread_cond_timedwait+0x168
#
# An error report file with more information is saved as hs_err_pid7668.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
make: *** [out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes.dex] 已放棄 (core dumped)
解決:
虛擬機(jī)給的內(nèi)存512太小,給個(gè)1G試試。然后在本機(jī)里打開任務(wù)管理器,找到虛擬機(jī)進(jìn)程,優(yōu)先級(jí)設(shè)置為實(shí)時(shí)。給他最多東西。
錯(cuò)誤 5:
out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_get':
/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:27: undefined reference to `pthread_getspecific'
out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_set':
/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:36: undefined reference to `pthread_key_create'
/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:44: undefined reference to `pthread_setspecific'
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/localize_intermediates/localize] 錯(cuò)誤 1
解決:類似問(wèn)題3
修改./framework/base/tools/localize/Android.mk文件
ifeq ($(HOST_OS),linux)
#LOCAL_LDLIBS += -lrt 把這行注釋掉,改為下面一行。
LOCAL_LDLIBS += -lrt -lpthread
endif
執(zhí)行$sudo make PRODUCT-sdk-sdk命令,生成對(duì)應(yīng)于該版本源代碼的用于生產(chǎn)環(huán)境的sdk。
編譯的SDK版本,實(shí)際位置是./out/host/linux-x86/sdk/android-sdk_eng.root_linux-x86。
因?yàn)樗容^常用,我們給它高優(yōu)先級(jí):
update-alternatives --install /usr/bin/AndroidSDK AndroidSDK ./out/host/linux-x86/sdk/android-sdk_eng.root_linux-x86 255
然后使用update-alternatives --display AndroidSDK查看當(dāng)前配置情況;
如果要切換配置,使用update-alternatives --config AndroidSDK。
配置AndroidSDK環(huán)境變量。終端中執(zhí)行g(shù)edit ~/.bashrc
在文件最后添加下面三行:
# set android environment
export ANDROID_SDK_HOME=/usr/bin/AndroidSDK
export PATH=$ANDROID_SDK_HOME/tools:$PATH
保存文件。在終端中執(zhí)行source ~/.bashrc
聯(lián)系客服