1page.title=Building the System 2@jd:body 3 4<!-- 5 Copyright 2013 The Android Open Source Project 6 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 27The following instructions to build the Android source tree apply to all branches, including master. 28 29<h2 id="choosing-a-branch">Choosing a Branch</h2> 30<p>Some of the requirements for your build environment are determined by which 31version of the source code you plan to compile. See 32<a href="build-numbers.html">Codenames, Tags, and Build Numbers</a> for a full listing of branches you may 33choose from. You may also choose to download and build the latest source code 34(called "master"), in which case you will simply omit the branch specification 35when you initialize the repository.</p> 36<p>Once you have selected a branch, follow the appropriate instructions below to 37set up your build environment.</p> 38 39 40<p>The basic sequence of build commands is as follows:</p> 41<h2 id="initialize">Initialize</h2> 42<p>Initialize the environment with the <code>envsetup.sh</code> script. Note 43that replacing "source" with a single dot saves a few characters, 44and the short form is more commonly used in documentation.</p> 45<pre><code>$ source build/envsetup.sh 46</code></pre> 47<p>or</p> 48<pre><code>$ . build/envsetup.sh 49</code></pre> 50<h2 id="choose-a-target">Choose a Target</h2> 51<p>Choose which target to build with <code>lunch</code>. The exact configuration can be passed as 52an argument, e.g. </p> 53<pre><code>$ lunch aosp_arm-eng 54</code></pre> 55<p>The example above refers to a complete build for the emulator, with all debugging enabled.</p> 56<p>If run with no arguments <code>lunch</code> will prompt you to choose a target from the menu. </p> 57<p>All build targets take the form BUILD-BUILDTYPE, where the BUILD is a codename 58referring to the particular feature combination. Here's a partial list:</p> 59<table> 60<thead> 61<tr> 62<th>Build name</th> 63<th>Device</th> 64<th>Notes</th> 65</tr> 66</thead> 67<tbody> 68<tr> 69<td>aosp_arm</td> 70<td>ARM emulator</td> 71<td>AOSP, fully configured with all languages, apps, input methods</td> 72</tr> 73<tr> 74<td>aosp_maguro</td> 75<td>maguro</td> 76<td>AOSP, running on Galaxy Nexus GSM/HSPA+ ("maguro")</td> 77</tr> 78<tr> 79<td>aosp_panda</td> 80<td>panda</td> 81<td>AOSP, running on PandaBoard ("panda")</td> 82</tr> 83</tbody> 84</table> 85<p>and the BUILDTYPE is one of the following:</p> 86<table> 87<thead> 88<tr> 89<th>Buildtype</th> 90<th>Use</th> 91</tr> 92</thead> 93<tbody> 94<tr> 95<td>user</td> 96<td>limited access; suited for production</td> 97</tr> 98<tr> 99<td>userdebug</td> 100<td>like "user" but with root access and debuggability; preferred for debugging</td> 101</tr> 102<tr> 103<td>eng</td> 104<td>development configuration with additional debugging tools</td> 105</tr> 106</tbody> 107</table> 108<p>For more information about building for and running on actual hardware, see 109<a href="building-devices.html">Building for Devices</a>.</p> 110<h2 id="build-the-code">Build the Code</h2> 111<p>Build everything with <code>make</code>. GNU make can handle parallel 112tasks with a <code>-jN</code> argument, and it's common to use a number of 113tasks N that's between 1 and 2 times the number of hardware 114threads on the computer being used for the build. E.g. on a 115dual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core), 116the fastest builds are made with commands between <code>make -j16</code> and 117<code>make -j32</code>.</p> 118<pre><code>$ make -j4 119</code></pre> 120<h2 id="run-it">Run It!</h2> 121<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> 122<h3 id="flash-a-device">Flash a Device</h3> 123<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> 124<pre><code>$ adb reboot bootloader 125</code></pre> 126<p>Once the device is in fastboot mode, run </p> 127<pre><code>$ fastboot flashall -w 128</code></pre> 129<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> 130<p>For more information about building for and running on actual hardware, see 131<a href="building-devices.html">Building for Devices.</a></p> 132<h3 id="emulate-an-android-device">Emulate an Android Device</h3> 133<p>The emulator is added to your path automatically by the build process. To run the emulator, type</p> 134<pre><code>$ emulator 135</code></pre> 136<h2 id="using-ccache">Using ccache</h2> 137<p>ccache is a compiler cache for C and C++ that can help make builds faster. 138In the root of the source tree, do the following:</p> 139<pre><code>$ export USE_CCACHE=1 140$ export CCACHE_DIR=/<path_of_your_choice>/.ccache 141$ prebuilts/misc/linux-x86/ccache/ccache -M 50G 142</code></pre> 143<p>The suggested cache size is 50-100G.</p> 144<p>You can watch ccache being used by doing the following:</p> 145<pre><code>$ watch -n1 -d prebuilts/misc/linux-x86/ccache/ccache -s 146</code></pre> 147<p>On OSX, you should replace <code>linux-x86</code> with <code>darwin-x86</code>.</p> 148<p>When using Ice Cream Sandwich (4.0.x) or older, you should replace 149<code>prebuilts/misc</code> with <code>prebuilt</code>.</p> 150<h2 id="troubleshooting-common-build-errors">Troubleshooting Common Build Errors</h2> 151<h3 id="wrong-java-version">Wrong Java Version</h3> 152<p>If you are attempting to build a version of Android inconsistent with your 153version of Java, <code>make</code> will abort with a message such as</p> 154<pre><code>************************************************************ 155You are attempting to build with the incorrect version 156of java. 157 158Your version is: WRONG_VERSION. 159The correct version is: RIGHT_VERSION. 160 161Please follow the machine setup instructions at 162 https://source.android.com/source/download.html 163************************************************************ 164</code></pre> 165<p>This may be caused by:</p> 166<ul> 167<li> 168<p>Failing to install the correct JDK as specified in <a href="initializing.html">Initializing the Build Environment</a>.</p> 169</li> 170<li> 171<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> 172</li> 173</ul> 174<h3 id="python-version-3">Python Version 3</h3> 175<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> 176<pre><code>$ apt-get install python 177</code></pre> 178<h3 id="case-insensitive-filesystem">Case Insensitive Filesystem</h3> 179<p>If you are building on an HFS filesystem on Mac OS X, you may encounter an error such as</p> 180<pre><code>************************************************************ 181You are building on a case-insensitive filesystem. 182Please move your source tree to a case-sensitive filesystem. 183************************************************************ 184</code></pre> 185<p>Please follow the instructions in <a href="initializing.html">Initializing the Build Environment</a> for creating a case-sensitive disk image.</p> 186<h3 id="no-usb-permission">No USB Permission</h3> 187<p>On most Linux systems, unprivileged users cannot access USB ports by default. If you see a permission denied error, follow the instructions 188<a href="initializing.html">Initializing the Build Environment</a> for configuring USB access. </p> 189<p>If adb was already running and cannot connect to the device after 190getting those rules set up, it can be killed with <code>adb kill-server</code>. 191That will cause adb to restart with the new configuration.</p> 192