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