1page.title=Building the System 2@jd:body 3 4<!-- 5 Copyright 2015 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 27<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> 30 31<h2 id="initialize">Initialize</h2> 32<p>Initialize the environment with the <code>envsetup.sh</code> script. Note 33that replacing <code>source</code> with <code>.</code> (a single dot) saves a few characters, 34and 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> 40 41<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 43an argument. For example, the following command:</p> 44<pre><code>$ lunch aosp_arm-eng 45</code></pre> 46<p>refers to a complete build for the emulator, with all debugging enabled.</p> 47<p>If run with no arguments <code>lunch</code> will prompt you to choose a target from the menu. </p> 48<p>All build targets take the form <code>BUILD-BUILDTYPE</code>, where the <code>BUILD</code> is a codename 49referring to the particular feature combination.</p> 50 51<p>The BUILDTYPE is one of the following:</p> 52<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> 76 77<h2 id="build-the-code">Build the code</h2> 78<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 81threads on the computer being used for the build. For example, on a 82dual-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> 96<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> 97<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> 103<h2 id="using-ccache">Using ccache</h2> 104<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=/<path_of_your_choice>/.ccache 108$ prebuilts/misc/linux-x86/ccache/ccache -M 50G 109</code></pre> 110<p>The suggested cache size is 50-100G.</p> 111<p>On Linux, you can watch ccache being used by doing the following:</p> 112<pre><code>$ watch -n1 -d prebuilts/misc/linux-x86/ccache/ccache -s 113</code></pre> 114<p>On Mac OS, you should replace <code>linux-x86</code> with <code>darwin-x86</code>.</p> 115<p>When using Ice Cream Sandwich (4.0.x) or older, you should replace 116<code>prebuilts/misc</code> with <code>prebuilt</code>.</p> 117<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> 121<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> 132<p>This may be caused by:</p> 133<ul> 134<li> 135<p>Failing to install the correct JDK as specified in <a href="initializing.html">Initializing the Build Environment</a>.</p> 136</li> 137<li> 138<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> 139</li> 140</ul> 141<h3 id="python-version-3">Python Version 3</h3> 142<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> 145<h3 id="case-insensitive-filesystem">Case Insensitive Filesystem</h3> 146<p>If you are building on an HFS filesystem on Mac OS, you may encounter an error such as</p> 147<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> 153<h3 id="no-usb-permission">No USB Permission</h3> 154<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> 159