Skyler Kaufman | 4443691 | 2011-04-07 15:11:52 -0700 | [diff] [blame] | 1 | <!-- |
| 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 Kaufman | 991ae4d | 2011-04-07 12:30:41 -0700 | [diff] [blame] | 17 | # Building the System # |
| 18 | |
| 19 | The basic sequence of build commands is as follows: |
| 20 | |
| 21 | ## Initialize ## |
| 22 | |
| 23 | Initialize the environment with the `envsetup.sh` script. Note |
| 24 | that replacing "source" with a single dot saves a few characters, |
| 25 | and the short form is more commonly used in documentation. |
| 26 | |
| 27 | $ source build/envsetup.sh |
| 28 | |
| 29 | or |
| 30 | |
| 31 | $ . build/envsetup.sh |
| 32 | |
| 33 | ## Choose a Target ## |
| 34 | |
| 35 | Choose which target to build with `lunch`. The exact configuration can be passed as |
| 36 | an argument, e.g. |
| 37 | |
| 38 | $ lunch full-eng |
| 39 | |
Skyler Kaufman | 4443691 | 2011-04-07 15:11:52 -0700 | [diff] [blame] | 40 | The example above refers to a complete build for the emulator, with all debugging enabled. |
Skyler Kaufman | 991ae4d | 2011-04-07 12:30:41 -0700 | [diff] [blame] | 41 | |
| 42 | If run with no arguments `lunch` will prompt you to choose a target from the menu. |
| 43 | |
Jean-Baptiste Queru | b4d39b4 | 2011-04-11 13:53:58 -0700 | [diff] [blame] | 44 | All build targets take the form BUILD-BUILDTYPE, where the BUILD is a codename |
| 45 | referring to the particular feature combination: |
Skyler Kaufman | 991ae4d | 2011-04-07 12:30:41 -0700 | [diff] [blame] | 46 | |
Jean-Baptiste Queru | ddaee66 | 2011-05-17 15:07:48 -0700 | [diff] [blame^] | 47 | Build name | Device | Notes |
| 48 | ------------|----------|--------------------------- |
Jean-Baptiste Queru | b4d39b4 | 2011-04-11 13:53:58 -0700 | [diff] [blame] | 49 | generic | emulator | lowest-common denominator |
| 50 | full | emulator | fully configured with all languages, apps, input methods |
| 51 | full_crespo | crespo | `full` build running on Nexus S ("crespo") |
Skyler Kaufman | 991ae4d | 2011-04-07 12:30:41 -0700 | [diff] [blame] | 52 | |
| 53 | and the BUILDTYPE is one of the following: |
| 54 | |
| 55 | Buildtype | Use |
| 56 | ------------|-------------------------------------- |
| 57 | user | limited access; suited for production |
Jean-Baptiste Queru | b4d39b4 | 2011-04-11 13:53:58 -0700 | [diff] [blame] | 58 | userdebug | like "user" but with root access and debuggability; preferred for debugging |
| 59 | eng | development configuration with additional debugging tools |
| 60 | |
| 61 | For more information about building for and running on actual hardware, see |
| 62 | [Building for devices](building-devices.html) |
Skyler Kaufman | 991ae4d | 2011-04-07 12:30:41 -0700 | [diff] [blame] | 63 | |
| 64 | ## Build the Code ## |
| 65 | |
| 66 | Build everything with `make`. GNU make can handle parallel |
| 67 | tasks with a `-jN` argument, and it's common to use a number of |
| 68 | tasks N that's between 1 and 2 times the number of hardware |
| 69 | threads on the computer being used for the build. E.g. on a |
| 70 | dual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core), |
| 71 | the fastest builds are made with commands between `make -j16` and |
| 72 | `make -j32`. |
| 73 | |
| 74 | $ make -j4 |
| 75 | |
| 76 | ## Run It! ## |
| 77 | |
| 78 | 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 `lunch`, and it is unlikely at best to run on a different target than it was built for. |
| 79 | |
| 80 | ### Flash a Device ### |
| 81 | |
| 82 | To 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 | |
| 86 | Once the device is in fastboot mode, run |
| 87 | |
| 88 | $ fastboot flashall -w |
| 89 | |
| 90 | The `-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 Queru | b4d39b4 | 2011-04-11 13:53:58 -0700 | [diff] [blame] | 92 | For more information about building for and running on actual hardware, see |
| 93 | [Building for devices](building-devices.html) |
| 94 | |
Skyler Kaufman | 991ae4d | 2011-04-07 12:30:41 -0700 | [diff] [blame] | 95 | ### Emulate an Android Device ### |
| 96 | |
| 97 | The emulator is added to your path automatically by the build process. To run the emulator, type |
| 98 | |
| 99 | $ emulator |
| 100 | |
| 101 | |
| 102 | # Troubleshooting Common Build Errors # |
| 103 | |
| 104 | ## Wrong Java Version ## |
| 105 | |
| 106 | If you are attempting to build froyo or earlier with Java 1.6, or gingerbread or later |
| 107 | with Java 1.5, `make` will abort with a message such as |
| 108 | |
| 109 | ************************************************************ |
| 110 | You are attempting to build with the incorrect version |
| 111 | of java. |
| 112 | |
| 113 | Your version is: WRONG_VERSION. |
| 114 | The correct version is: RIGHT_VERSION. |
| 115 | |
| 116 | Please follow the machine setup instructions at |
| 117 | http://source.android.com/download |
| 118 | ************************************************************ |
| 119 | |
| 120 | This may be caused by |
| 121 | |
| 122 | - 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. |
| 123 | |
| 124 | - another JDK that you previously installed appearing in your path. You can remove the offending JDK from your path with: |
| 125 | |
| 126 | $ export PATH=${PATH/\/path\/to\/jdk\/dir:/} |
| 127 | |
| 128 | ## Python Version 3 ## |
| 129 | |
| 130 | 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: |
| 131 | |
| 132 | $ apt-get install python |
| 133 | |
| 134 | ## Gmake Version 3.82 ## |
| 135 | |
| 136 | There is a bug in `make` version 3.82 on Mac OS that prevents building Android. |
| 137 | |
| 138 | TODO: what the error looks like with GNU make 3.82 on older builds that don't explicitly detect it. |
| 139 | |
| 140 | Follow the instructions on the [Initializing](initializing.html) page for reverting GNU make from 3.82 to 3.81. |
| 141 | |
| 142 | ## Case Insensitive Filesystem ## |
| 143 | |
| 144 | If you are building on an HFS filesystem on Mac OS X, you may encounter an error such as |
| 145 | |
| 146 | ************************************************************ |
| 147 | You are building on a case-insensitive filesystem. |
| 148 | Please move your source tree to a case-sensitive filesystem. |
| 149 | ************************************************************ |
| 150 | |
| 151 | Please follow the instructions on the [Initializing](initializing.html) page for creating a case-sensitive disk image. |
| 152 | |
| 153 | ## No USB Permission ## |
| 154 | |
Skyler Kaufman | 4443691 | 2011-04-07 15:11:52 -0700 | [diff] [blame] | 155 | On 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 Kaufman | 991ae4d | 2011-04-07 12:30:41 -0700 | [diff] [blame] | 156 | |
| 157 | If adb was already running and cannot connect to the device after |
| 158 | getting those rules set up, it can be killed with `adb kill-server`. |
| 159 | That will cause adb to restart with the new configuration. |
| 160 | |