blob: e2de012084462078b978a6f21e28cfe358f6b546 [file] [log] [blame] [view]
Skyler Kaufman44436912011-04-07 15:11:52 -07001<!--
2 Copyright 2010 The Android Open Source Project
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15-->
16
Skyler Kaufman991ae4d2011-04-07 12:30:41 -070017# Building the System #
18
19The basic sequence of build commands is as follows:
20
21## Initialize ##
22
23Initialize the environment with the `envsetup.sh` script. Note
24that replacing "source" with a single dot saves a few characters,
25and the short form is more commonly used in documentation.
26
27 $ source build/envsetup.sh
28
29or
30
31 $ . build/envsetup.sh
32
33## Choose a Target ##
34
35Choose which target to build with `lunch`. The exact configuration can be passed as
36an argument, e.g.
37
38 $ lunch full-eng
39
Skyler Kaufman44436912011-04-07 15:11:52 -070040The example above refers to a complete build for the emulator, with all debugging enabled.
Skyler Kaufman991ae4d2011-04-07 12:30:41 -070041
42If run with no arguments `lunch` will prompt you to choose a target from the menu.
43
Jean-Baptiste Querub4d39b42011-04-11 13:53:58 -070044All build targets take the form BUILD-BUILDTYPE, where the BUILD is a codename
Jean-Baptiste Queruc10820f2012-07-17 13:33:48 -070045referring to the particular feature combination. Here's a partial list:
Skyler Kaufman991ae4d2011-04-07 12:30:41 -070046
Jean-Baptiste Queruddaee662011-05-17 15:07:48 -070047Build name | Device | Notes
48------------|----------|---------------------------
Jean-Baptiste Querub4d39b42011-04-11 13:53:58 -070049full | emulator | fully configured with all languages, apps, input methods
Jean-Baptiste Queru3e466b02011-10-06 14:34:00 -070050full_maguro | maguro | `full` build running on Galaxy Nexus GSM/HSPA+ ("maguro")
51full_panda | panda | `full` build running on PandaBoard ("panda")
Skyler Kaufman991ae4d2011-04-07 12:30:41 -070052
53and the BUILDTYPE is one of the following:
54
55Buildtype | Use
56------------|--------------------------------------
57user | limited access; suited for production
Jean-Baptiste Querub4d39b42011-04-11 13:53:58 -070058userdebug | like "user" but with root access and debuggability; preferred for debugging
59eng | development configuration with additional debugging tools
60
61For more information about building for and running on actual hardware, see
62[Building for devices](building-devices.html)
Skyler Kaufman991ae4d2011-04-07 12:30:41 -070063
64## Build the Code ##
65
66Build everything with `make`. GNU make can handle parallel
67tasks with a `-jN` argument, and it's common to use a number of
68tasks N that's between 1 and 2 times the number of hardware
69threads on the computer being used for the build. E.g. on a
70dual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core),
71the fastest builds are made with commands between `make -j16` and
72`make -j32`.
73
74 $ make -j4
75
76## Run It! ##
77
78You 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.
79
80### Flash a Device ###
81
82To 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
83
84 $ adb reboot bootloader
85
86Once the device is in fastboot mode, run
87
88 $ fastboot flashall -w
89
90The `-w` option wipes the `/data` partition on the device; this is useful for your first time flashing a particular device, but is otherwise unnecessary.
91
Jean-Baptiste Querub4d39b42011-04-11 13:53:58 -070092For more information about building for and running on actual hardware, see
93[Building for devices](building-devices.html)
94
Skyler Kaufman991ae4d2011-04-07 12:30:41 -070095### Emulate an Android Device ###
96
97The emulator is added to your path automatically by the build process. To run the emulator, type
98
99 $ emulator
100
Conley Owens62908652011-06-21 14:25:32 -0700101# Using ccache #
102
103ccache is a compiler cache for C and C++ that can help make builds faster.
104In the root of the source tree, do the following:
105
106 $ export USE_CCACHE=1
107 $ export CCACHE_DIR=/<path_of_your_choice>/.ccache
Jean-Baptiste Querud492e972012-08-21 09:36:42 -0700108 $ prebuilts/misc/linux-x86/ccache/ccache -M 50G
109
110The suggested cache size is 50-100G.
Conley Owens62908652011-06-21 14:25:32 -0700111
112You can watch ccache being used by doing the following:
113
Jean-Baptiste Querud492e972012-08-21 09:36:42 -0700114 $ watch -n1 -d prebuilts/misc/linux-x86/ccache/ccache -s
Conley Owens62908652011-06-21 14:25:32 -0700115
116On OSX, you should replace `linux-x86` with `darwin-x86`.
Skyler Kaufman991ae4d2011-04-07 12:30:41 -0700117
Jean-Baptiste Querud492e972012-08-21 09:36:42 -0700118When using Ice Cream Sandwich (4.0.x) or older, you should replace
119`prebuilts/misc` with `prebuilt`.
120
Skyler Kaufman991ae4d2011-04-07 12:30:41 -0700121# Troubleshooting Common Build Errors #
122
123## Wrong Java Version ##
124
125If you are attempting to build froyo or earlier with Java 1.6, or gingerbread or later
126with Java 1.5, `make` will abort with a message such as
127
128 ************************************************************
129 You are attempting to build with the incorrect version
130 of java.
131
132 Your version is: WRONG_VERSION.
133 The correct version is: RIGHT_VERSION.
134
135 Please follow the machine setup instructions at
Jean-Baptiste Queru60c81412012-04-19 15:00:44 -0700136 https://source.android.com/source/download.html
Skyler Kaufman991ae4d2011-04-07 12:30:41 -0700137 ************************************************************
138
139This may be caused by
140
141- failing to install the correct JDK as specified on the [Initializing](initializing.html) page. Building Android requires Sun JDK 5 or 6 depending on which release you are building.
142
143- another JDK that you previously installed appearing in your path. You can remove the offending JDK from your path with:
144
145 $ export PATH=${PATH/\/path\/to\/jdk\/dir:/}
146
147## Python Version 3 ##
148
149Repo 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:
150
151 $ apt-get install python
152
Skyler Kaufman991ae4d2011-04-07 12:30:41 -0700153## Case Insensitive Filesystem ##
154
155If you are building on an HFS filesystem on Mac OS X, you may encounter an error such as
156
157 ************************************************************
158 You are building on a case-insensitive filesystem.
159 Please move your source tree to a case-sensitive filesystem.
160 ************************************************************
161
162Please follow the instructions on the [Initializing](initializing.html) page for creating a case-sensitive disk image.
163
164## No USB Permission ##
165
Skyler Kaufman44436912011-04-07 15:11:52 -0700166On most Linux systems, unprivileged users cannot access USB ports by default. If you see a permission denied error, follow the instructions on the [Initializing](initializing.html) page for configuring USB access.
Skyler Kaufman991ae4d2011-04-07 12:30:41 -0700167
168If adb was already running and cannot connect to the device after
169getting those rules set up, it can be killed with `adb kill-server`.
170That will cause adb to restart with the new configuration.
171