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