1 <html devsite> 2 <head> 3 <title>Downloading the Source</title> 4 <meta name="project_path" value="/_project.yaml" /> 5 <meta name="book_path" value="/_book.yaml" /> 6 </head> 7 <body> 8 <!-- 9 Copyright 2017 The Android Open Source Project 10 11 Licensed under the Apache License, Version 2.0 (the "License"); 12 you may not use this file except in compliance with the License. 13 You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 --> 23 24 25 26 <p> 27 The Android source tree is located in a Git repository hosted by Google. The Git repository 28 includes metadata for the Android source, including those related to changes to the source 29 and the date they were made. This document describes how to download the source tree for a 30 specific Android code-line. 31 </p> 32 <p> 33 To instead start with a factory image for a specific device, see 34 <a href="running.html#selecting-device-build">Selecting a device build</a>. 35 </p> 36 <h2 id="installing-repo"> 37 Installing Repo 38 </h2> 39 <p> 40 Repo is a tool that makes it easier to work with Git in the context of Android. For more 41 information about Repo, see the <a href="developing.html">Developing</a> section. 42 </p> 43 <p> 44 To install Repo: 45 </p> 46 <ol> 47 <li> 48 <p> 49 Make sure you have a bin/ directory in your home directory and that it is included in 50 your path: 51 </p> 52 <pre class="devsite-click-to-copy"> 53 <code class="devsite-terminal">mkdir ~/bin</code> 54 <code class="devsite-terminal">PATH=~/bin:$PATH</code> 55 </pre> 56 </li> 57 <li> 58 <p> 59 Download the Repo tool and ensure that it is executable: 60 </p> 61 <pre class="devsite-click-to-copy"> 62 <code class="devsite-terminal">curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo</code> 63 <code class="devsite-terminal">chmod a+x ~/bin/repo</code> 64 </pre> 65 </li> 66 </ol> 67 <p> 68 For version 1.21, the SHA-1 checksum for repo is b8bd1804f432ecf1bab730949c82b93b0fc5fede 69 </p> 70 <p> 71 For version 1.22, the SHA-1 checksum for repo is da0514e484f74648a890c0467d61ca415379f791 72 </p> 73 <p> 74 For version 1.23, the SHA-256 checksum for repo is e147f0392686c40cfd7d5e6f332c6ee74c4eab4d24e2694b3b0a0c037bf51dc5 75 </p> 76 <h2 id="initializing-a-repo-client"> 77 Initializing a Repo client 78 </h2> 79 <p> 80 After installing Repo, set up your client to access the Android source repository: 81 </p> 82 <ol> 83 <li> 84 <p> 85 Create an empty directory to hold your working files. If you're using MacOS, this has to 86 be on a case-sensitive filesystem. Give it any name you like: 87 </p> 88 <pre class="devsite-click-to-copy"> 89 <code class="devsite-terminal">mkdir WORKING_DIRECTORY</code> 90 <code class="devsite-terminal">cd WORKING_DIRECTORY</code> 91 </pre> 92 </li> 93 <li> 94 <p> 95 Configure git with your real name and email address. To use the Gerrit code-review tool, 96 you will need an email address that is connected with a <a href= 97 "https://www.google.com/accounts">registered Google account</a>. Make sure this is a live 98 address at which you can receive messages. The name that you provide here will show up in 99 attributions for your code submissions. 100 </p> 101 <pre class="devsite-click-to-copy"> 102 <code class="devsite-terminal">git config --global user.name "Your Name"</code> 103 <code class="devsite-terminal">git config --global user.email "you (a] example.com"</code> 104 </pre> 105 </li> 106 <li> 107 <p> 108 Run <code>repo init</code> to bring down the latest version of Repo with all its most 109 recent bug fixes. You must specify a URL for the manifest, which specifies where the 110 various repositories included in the Android source will be placed within your working 111 directory. 112 </p> 113 <pre class="devsite-terminal devsite-click-to-copy"> 114 repo init -u https://android.googlesource.com/platform/manifest 115 </pre> 116 <p> 117 To check out a branch other than "master", specify it with <code>-b</code>. For a list of branches, see <a href="build-numbers.html#source-code-tags-and-builds">Source Code Tags and Builds</a>. 118 </p> 119 <pre class="devsite-terminal devsite-click-to-copy"> 120 repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1 121 </pre> 122 </li> 123 </ol> 124 <p> 125 A successful initialization will end with a message stating that Repo is initialized in your 126 working directory. Your client directory should now contain a <code>.repo</code> directory 127 where files such as the manifest will be kept. 128 </p> 129 <h2 id="getting-the-files"> 130 Downloading the Android Source Tree 131 </h2> 132 <p> 133 To pull down the Android source tree to your working directory from the repositories as 134 specified in the default manifest, run 135 </p> 136 <pre class="devsite-terminal devsite-click-to-copy">repo sync</pre> 137 <p> 138 The Android source files will be located in your working directory under their project names. 139 The initial sync operation will take an hour or more to complete. For more about <code>repo 140 sync</code> and other Repo commands, see the <a href="developing.html">Developing</a> section. 141 </p> 142 <h2 id="using-authentication"> 143 Using Authentication 144 </h2> 145 <p> 146 By default, access to the Android source code is anonymous. To protect the servers against 147 excessive usage, each IP address is associated with a quota. 148 </p> 149 <p> 150 When sharing an IP address with other users (e.g. when accessing the source repositories from 151 beyond a NAT firewall), the quotas can trigger even for regular usage patterns (e.g. if many 152 users sync new clients from the same IP address within a short period). 153 </p> 154 <p> 155 In that case, it is possible to use authenticated access, which then uses a separate quota 156 for each user, regardless of the IP address. 157 </p> 158 <p> 159 The first step is to create a password with <a href= 160 "https://android.googlesource.com/new-password">the password generator</a> 161 and follow the instructions on the password generator page. 162 </p> 163 <p> 164 The second step is to force authenticated access, by using the following manifest URI: 165 <code>https://android.googlesource.com/a/platform/manifest</code>. Notice how the 166 <code>/a/</code> directory prefix triggers mandatory authentication. You can convert an 167 existing client to use mandatory authentication with the following command: 168 </p> 169 <pre class="devsite-terminal devsite-click-to-copy"> 170 repo init -u https://android.googlesource.com/a/platform/manifest 171 </pre> 172 <h2 id="troubleshooting-network-issues"> 173 Troubleshooting network issues 174 </h2> 175 <p> 176 When downloading from behind a proxy (which is common in some corporate environments), it 177 might be necessary to explicitly specify the proxy that is then used by repo: 178 </p> 179 <pre class="devsite-click-to-copy"> 180 <code class="devsite-terminal">export HTTP_PROXY=http://<proxy_user_id>:<proxy_password>@<proxy_server>:<proxy_port></code> 181 <code class="devsite-terminal">export HTTPS_PROXY=http://<proxy_user_id>:<proxy_password>@<proxy_server>:<proxy_port></code> 182 </pre> 183 <p> 184 More rarely, Linux clients experience connectivity issues, getting stuck in the middle of 185 downloads (typically during "Receiving objects"). It has been reported that tweaking the 186 settings of the TCP/IP stack and using non-parallel commands can improve the situation. You 187 need root access to modify the TCP setting: 188 </p> 189 <pre class="devsite-click-to-copy"> 190 <code class="devsite-terminal">sudo sysctl -w net.ipv4.tcp_window_scaling=0</code> 191 <code class="devsite-terminal">repo sync -j1</code> 192 </pre> 193 <h2 id="using-a-local-mirror"> 194 Using a local mirror 195 </h2> 196 <p> 197 When using several clients, especially in situations where bandwidth is scarce, it is better 198 to create a local mirror of the entire server content, and to sync clients from that mirror 199 (which requires no network access). The download for a full mirror is smaller than the 200 download of two clients, while containing more information. 201 </p> 202 <p> 203 These instructions assume that the mirror is created in <code>/usr/local/aosp/mirror</code>. 204 The first step is to create and sync the mirror itself. Notice the <code>--mirror</code> flag, which 205 can be specified only when creating a new client: 206 </p> 207 <pre class="devsite-click-to-copy"> 208 <code class="devsite-terminal">mkdir -p /usr/local/aosp/mirror</code> 209 <code class="devsite-terminal">cd /usr/local/aosp/mirror</code> 210 <code class="devsite-terminal">repo init -u https://android.googlesource.com/mirror/manifest --mirror</code> 211 <code class="devsite-terminal">repo sync</code> 212 </pre> 213 <p> 214 Once the mirror is synced, new clients can be created from it. Note that it's important to 215 specify an absolute path: 216 </p> 217 <pre class="devsite-click-to-copy"> 218 <code class="devsite-terminal">mkdir -p /usr/local/aosp/master</code> 219 <code class="devsite-terminal">cd /usr/local/aosp/master</code> 220 <code class="devsite-terminal">repo init -u /usr/local/aosp/mirror/platform/manifest.git</code> 221 <code class="devsite-terminal">repo sync</code> 222 </pre> 223 <p> 224 Finally, to sync a client against the server, the mirror needs to be synced against the 225 server, then the client against the mirror: 226 </p> 227 <pre class="devsite-click-to-copy"> 228 <code class="devsite-terminal">cd /usr/local/aosp/mirror</code> 229 <code class="devsite-terminal">repo sync</code> 230 <code class="devsite-terminal">cd /usr/local/aosp/master</code> 231 <code class="devsite-terminal">repo sync</code> 232 </pre> 233 <p> 234 It's possible to store the mirror on a LAN server and to access it over NFS, SSH or Git. It's 235 also possible to store it on a removable drive and to pass that drive around between users or 236 between machines. 237 </p> 238 <h2 id="verifying-git-tags"> 239 Verifying Git Tags 240 </h2> 241 <p> 242 Load the following public key into your GnuPG key database. The key is used to sign annotated 243 tags that represent releases. 244 </p> 245 <pre class="devsite-terminal devsite-click-to-copy"> 246 gpg --import 247 </pre> 248 <p> 249 Copy and paste the key below, then enter EOF (Ctrl-D) to end the input and process the 250 keys. 251 </p> 252 <pre class="devsite-click-to-copy"> 253 -----BEGIN PGP PUBLIC KEY BLOCK----- 254 Version: GnuPG v1.4.2.2 (GNU/Linux) 255 256 mQGiBEnnWD4RBACt9/h4v9xnnGDou13y3dvOx6/t43LPPIxeJ8eX9WB+8LLuROSV 257 lFhpHawsVAcFlmi7f7jdSRF+OvtZL9ShPKdLfwBJMNkU66/TZmPewS4m782ndtw7 258 8tR1cXb197Ob8kOfQB3A9yk2XZ4ei4ZC3i6wVdqHLRxABdncwu5hOF9KXwCgkxMD 259 u4PVgChaAJzTYJ1EG+UYBIUEAJmfearb0qRAN7dEoff0FeXsEaUA6U90sEoVks0Z 260 wNj96SA8BL+a1OoEUUfpMhiHyLuQSftxisJxTh+2QclzDviDyaTrkANjdYY7p2cq 261 /HMdOY7LJlHaqtXmZxXjjtw5Uc2QG8UY8aziU3IE9nTjSwCXeJnuyvoizl9/I1S5 262 jU5SA/9WwIps4SC84ielIXiGWEqq6i6/sk4I9q1YemZF2XVVKnmI1F4iCMtNKsR4 263 MGSa1gA8s4iQbsKNWPgp7M3a51JCVCu6l/8zTpA+uUGapw4tWCp4o0dpIvDPBEa9 264 b/aF/ygcR8mh5hgUfpF9IpXdknOsbKCvM9lSSfRciETykZc4wrRCVGhlIEFuZHJv 265 aWQgT3BlbiBTb3VyY2UgUHJvamVjdCA8aW5pdGlhbC1jb250cmlidXRpb25AYW5k 266 cm9pZC5jb20+iGAEExECACAFAknnWD4CGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIX 267 gAAKCRDorT+BmrEOeNr+AJ42Xy6tEW7r3KzrJxnRX8mij9z8tgCdFfQYiHpYngkI 268 2t09Ed+9Bm4gmEO5Ag0ESedYRBAIAKVW1JcMBWvV/0Bo9WiByJ9WJ5swMN36/vAl 269 QN4mWRhfzDOk/Rosdb0csAO/l8Kz0gKQPOfObtyYjvI8JMC3rmi+LIvSUT9806Up 270 hisyEmmHv6U8gUb/xHLIanXGxwhYzjgeuAXVCsv+EvoPIHbY4L/KvP5x+oCJIDbk 271 C2b1TvVk9PryzmE4BPIQL/NtgR1oLWm/uWR9zRUFtBnE411aMAN3qnAHBBMZzKMX 272 LWBGWE0znfRrnczI5p49i2YZJAjyX1P2WzmScK49CV82dzLo71MnrF6fj+Udtb5+ 273 OgTg7Cow+8PRaTkJEW5Y2JIZpnRUq0CYxAmHYX79EMKHDSThf/8AAwUIAJPWsB/M 274 pK+KMs/s3r6nJrnYLTfdZhtmQXimpoDMJg1zxmL8UfNUKiQZ6esoAWtDgpqt7Y7s 275 KZ8laHRARonte394hidZzM5nb6hQvpPjt2OlPRsyqVxw4c/KsjADtAuKW9/d8phb 276 N8bTyOJo856qg4oOEzKG9eeF7oaZTYBy33BTL0408sEBxiMior6b8LrZrAhkqDjA 277 vUXRwm/fFKgpsOysxC6xi553CxBUCH2omNV6Ka1LNMwzSp9ILz8jEGqmUtkBszwo 278 G1S8fXgE0Lq3cdDM/GJ4QXP/p6LiwNF99faDMTV3+2SAOGvytOX6KjKVzKOSsfJQ 279 hN0DlsIw8hqJc0WISQQYEQIACQUCSedYRAIbDAAKCRDorT+BmrEOeCUOAJ9qmR0l 280 EXzeoxcdoafxqf6gZlJZlACgkWF7wi2YLW3Oa+jv2QSTlrx4KLM= 281 =Wi5D 282 -----END PGP PUBLIC KEY BLOCK----- 283 </pre> 284 <p> 285 After importing the keys, you can verify any tag with 286 </p> 287 <pre class="devsite-terminal devsite-click-to-copy"> 288 git tag -v TAG_NAME 289 </pre> 290 <p> 291 If you haven't <a href="initializing.html#ccache">set up ccache</a> yet, now would be a good 292 time to do it. 293 </p> 294 295 </body> 296 </html> 297