blob: d9eb0bfa7a357a4b097cf30e5e0b692740156996 [file] [log] [blame]
Robert Ly35f2fda2013-01-29 16:27:05 -08001page.title=Building the System
2@jd:body
3
4<!--
Clay Murphy51f20642015-07-07 17:15:12 -07005 Copyright 2015 The Android Open Source Project
Robert Ly35f2fda2013-01-29 16:27:05 -08006
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18-->
19<div id="qv-wrapper">
20 <div id="qv">
21 <h2>In this document</h2>
22 <ol id="auto-toc">
23 </ol>
24 </div>
25</div>
26
Clay Murphy51f20642015-07-07 17:15:12 -070027<p>The following instructions to build the Android source tree apply to all
28branches, including <code>master</code>. The basic sequence of build commands
29is as follows:</p>
Robert Ly35f2fda2013-01-29 16:27:05 -080030
Robert Ly35f2fda2013-01-29 16:27:05 -080031<h2 id="initialize">Initialize</h2>
32<p>Initialize the environment with the <code>envsetup.sh</code> script. Note
Collin El-Hossariba472e92015-02-03 16:44:00 -080033that replacing <code>source</code> with <code>.</code> (a single dot) saves a few characters,
Robert Ly35f2fda2013-01-29 16:27:05 -080034and the short form is more commonly used in documentation.</p>
35<pre><code>$ source build/envsetup.sh
36</code></pre>
37<p>or</p>
38<pre><code>$ . build/envsetup.sh
39</code></pre>
Clay Murphy51f20642015-07-07 17:15:12 -070040
Robert Ly35f2fda2013-01-29 16:27:05 -080041<h2 id="choose-a-target">Choose a Target</h2>
42<p>Choose which target to build with <code>lunch</code>. The exact configuration can be passed as
Collin El-Hossariba472e92015-02-03 16:44:00 -080043an argument. For example, the following command:</p>
Jean-Baptiste Querud8fbf202013-06-18 14:51:12 -070044<pre><code>$ lunch aosp_arm-eng
Robert Ly35f2fda2013-01-29 16:27:05 -080045</code></pre>
Collin El-Hossariba472e92015-02-03 16:44:00 -080046<p>refers to a complete build for the emulator, with all debugging enabled.</p>
Robert Ly35f2fda2013-01-29 16:27:05 -080047<p>If run with no arguments <code>lunch</code> will prompt you to choose a target from the menu. </p>
Collin El-Hossariba472e92015-02-03 16:44:00 -080048<p>All build targets take the form <code>BUILD-BUILDTYPE</code>, where the <code>BUILD</code> is a codename
Clay Murphy51f20642015-07-07 17:15:12 -070049referring to the particular feature combination.</p>
50
51<p>The BUILDTYPE is one of the following:</p>
Robert Ly35f2fda2013-01-29 16:27:05 -080052<table>
53<thead>
54<tr>
55<th>Buildtype</th>
56<th>Use</th>
57</tr>
58</thead>
59<tbody>
60<tr>
61<td>user</td>
62<td>limited access; suited for production</td>
63</tr>
64<tr>
65<td>userdebug</td>
66<td>like "user" but with root access and debuggability; preferred for debugging</td>
67</tr>
68<tr>
69<td>eng</td>
70<td>development configuration with additional debugging tools</td>
71</tr>
72</tbody>
73</table>
74<p>For more information about building for and running on actual hardware, see
75<a href="building-devices.html">Building for Devices</a>.</p>
Clay Murphy51f20642015-07-07 17:15:12 -070076
77<h2 id="build-the-code">Build the code</h2>
Robert Ly35f2fda2013-01-29 16:27:05 -080078<p>Build everything with <code>make</code>. GNU make can handle parallel
79tasks with a <code>-jN</code> argument, and it's common to use a number of
80tasks N that's between 1 and 2 times the number of hardware
Collin El-Hossariba472e92015-02-03 16:44:00 -080081threads on the computer being used for the build. For example, on a
Robert Ly35f2fda2013-01-29 16:27:05 -080082dual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core),
83the fastest builds are made with commands between <code>make -j16</code> and
84<code>make -j32</code>.</p>
85<pre><code>$ make -j4
86</code></pre>
87<h2 id="run-it">Run It!</h2>
88<p>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 <code>lunch</code>, and it is unlikely at best to run on a different target than it was built for.</p>
89<h3 id="flash-a-device">Flash a Device</h3>
90<p>To flash a device, you will need to use <code>fastboot</code>, 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</p>
91<pre><code>$ adb reboot bootloader
92</code></pre>
93<p>Once the device is in fastboot mode, run </p>
94<pre><code>$ fastboot flashall -w
95</code></pre>
Collin El-Hossariba472e92015-02-03 16:44:00 -080096<p>The <code>-w</code> option wipes the <code>/data</code> partition on the device; this is useful for your first time flashing a particular device but is otherwise unnecessary.</p>
Robert Ly35f2fda2013-01-29 16:27:05 -080097<p>For more information about building for and running on actual hardware, see
98<a href="building-devices.html">Building for Devices.</a></p>
99<h3 id="emulate-an-android-device">Emulate an Android Device</h3>
100<p>The emulator is added to your path automatically by the build process. To run the emulator, type</p>
101<pre><code>$ emulator
102</code></pre>
Clay Murphy6d00f3b2014-03-26 17:39:24 -0700103<h2 id="using-ccache">Using ccache</h2>
Robert Ly35f2fda2013-01-29 16:27:05 -0800104<p>ccache is a compiler cache for C and C++ that can help make builds faster.
105In the root of the source tree, do the following:</p>
106<pre><code>$ export USE_CCACHE=1
107$ export CCACHE_DIR=/&lt;path_of_your_choice&gt;/.ccache
108$ prebuilts/misc/linux-x86/ccache/ccache -M 50G
109</code></pre>
110<p>The suggested cache size is 50-100G.</p>
Collin El-Hossariba472e92015-02-03 16:44:00 -0800111<p>On Linux, you can watch ccache being used by doing the following:</p>
Robert Ly35f2fda2013-01-29 16:27:05 -0800112<pre><code>$ watch -n1 -d prebuilts/misc/linux-x86/ccache/ccache -s
113</code></pre>
Collin El-Hossariba472e92015-02-03 16:44:00 -0800114<p>On Mac OS, you should replace <code>linux-x86</code> with <code>darwin-x86</code>.</p>
Robert Ly35f2fda2013-01-29 16:27:05 -0800115<p>When using Ice Cream Sandwich (4.0.x) or older, you should replace
116<code>prebuilts/misc</code> with <code>prebuilt</code>.</p>
Clay Murphy6d00f3b2014-03-26 17:39:24 -0700117<h2 id="troubleshooting-common-build-errors">Troubleshooting Common Build Errors</h2>
118<h3 id="wrong-java-version">Wrong Java Version</h3>
119<p>If you are attempting to build a version of Android inconsistent with your
120version of Java, <code>make</code> will abort with a message such as</p>
Robert Ly35f2fda2013-01-29 16:27:05 -0800121<pre><code>************************************************************
122You are attempting to build with the incorrect version
123of java.
124
125Your version is: WRONG_VERSION.
126The correct version is: RIGHT_VERSION.
127
128Please follow the machine setup instructions at
129 https://source.android.com/source/download.html
130************************************************************
131</code></pre>
Clay Murphy00f6eb02014-09-09 13:50:18 -0700132<p>This may be caused by:</p>
Robert Ly35f2fda2013-01-29 16:27:05 -0800133<ul>
134<li>
Clay Murphy00f6eb02014-09-09 13:50:18 -0700135<p>Failing to install the correct JDK as specified in <a href="initializing.html">Initializing the Build Environment</a>.</p>
Robert Ly35f2fda2013-01-29 16:27:05 -0800136</li>
137<li>
Clay Murphy00f6eb02014-09-09 13:50:18 -0700138<p>Another JDK previously installed appearing in your path. Prepend the correct JDK to the beginning of your PATH or remove the problematic JDK.</p>
Robert Ly35f2fda2013-01-29 16:27:05 -0800139</li>
140</ul>
Clay Murphy6d00f3b2014-03-26 17:39:24 -0700141<h3 id="python-version-3">Python Version 3</h3>
Robert Ly35f2fda2013-01-29 16:27:05 -0800142<p>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:</p>
143<pre><code>$ apt-get install python
144</code></pre>
Clay Murphy6d00f3b2014-03-26 17:39:24 -0700145<h3 id="case-insensitive-filesystem">Case Insensitive Filesystem</h3>
Collin El-Hossariba472e92015-02-03 16:44:00 -0800146<p>If you are building on an HFS filesystem on Mac OS, you may encounter an error such as</p>
Robert Ly35f2fda2013-01-29 16:27:05 -0800147<pre><code>************************************************************
148You are building on a case-insensitive filesystem.
149Please move your source tree to a case-sensitive filesystem.
150************************************************************
151</code></pre>
152<p>Please follow the instructions in <a href="initializing.html">Initializing the Build Environment</a> for creating a case-sensitive disk image.</p>
Clay Murphy6d00f3b2014-03-26 17:39:24 -0700153<h3 id="no-usb-permission">No USB Permission</h3>
Robert Ly35f2fda2013-01-29 16:27:05 -0800154<p>On most Linux systems, unprivileged users cannot access USB ports by default. If you see a permission denied error, follow the instructions
155<a href="initializing.html">Initializing the Build Environment</a> for configuring USB access. </p>
156<p>If adb was already running and cannot connect to the device after
157getting those rules set up, it can be killed with <code>adb kill-server</code>.
158That will cause adb to restart with the new configuration.</p>