1 Copyright (C) 2009 The Android Open Source Project 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 15 16 Subject: How to build an Android SDK & ADT Eclipse plugin. 17 Date: 2009/03/27 18 Updated: 2013/04/09 19 20 21 Table of content: 22 0- License 23 1- Foreword 24 2- Building an SDK for MacOS and Linux 25 3- Building an SDK for Windows 26 4- Building an ADT plugin for Eclipse 27 5- Conclusion 28 29 30 31 ---------- 32 0- License 33 ---------- 34 35 Copyright (C) 2009 The Android Open Source Project 36 37 Licensed under the Apache License, Version 2.0 (the "License"); 38 you may not use this file except in compliance with the License. 39 You may obtain a copy of the License at 40 41 http://www.apache.org/licenses/LICENSE-2.0 42 43 Unless required by applicable law or agreed to in writing, software 44 distributed under the License is distributed on an "AS IS" BASIS, 45 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 46 See the License for the specific language governing permissions and 47 limitations under the License. 48 49 50 51 ----------- 52 1- Foreword 53 ----------- 54 55 This document explains how to build the Android SDK and the ADT Eclipse plugin. 56 57 It is designed for advanced users which are proficient with command-line 58 operations and know how to setup the pre-required software. 59 60 Basically it's not trivial yet when done right it's not that complicated. 61 62 63 64 -------------------------------------- 65 2- Building an SDK for MacOS and Linux 66 -------------------------------------- 67 68 First, setup your development environment and get the Android source code from 69 git as explained here: 70 71 http://source.android.com/source/download.html 72 73 For example for the cupcake branch: 74 75 $ mkdir ~/my-android-git 76 $ cd ~/my-android-git 77 $ repo init -u https://android.googlesource.com/platform/manifest -b master -g all,-notdefault,tools 78 $ repo sync 79 80 Then once you have all the source, simply build the SDK using: 81 82 $ cd ~/my-android-git 83 $ . build/envsetup.sh 84 $ lunch sdk-eng 85 $ make sdk 86 87 This will take a while, maybe between 20 minutes and several hours depending on 88 your machine. After a while you'll see this in the output: 89 90 Package SDK: out/host/darwin-x86/sdk/android-sdk_eng.<build-id>_mac-x86.zip 91 92 Some options: 93 94 - Depending on your machine you can tell 'make' to build more things in 95 parallel, e.g. if you have a dual core, use "make -j4 sdk" to build faster. 96 97 - You can define "BUILD_NUMBER" to control the build identifier that gets 98 incorporated in the resulting archive. The default is to use your username. 99 One suggestion is to include the date, e.g.: 100 101 $ export BUILD_NUMBER=${USER}-`date +%Y%m%d-%H%M%S` 102 103 There are certain characters you should avoid in the build number, typically 104 everything that might confuse 'make' or your shell. So for example avoid 105 punctuation and characters like $ & : / \ < > , and . 106 107 108 109 ------------------------------ 110 3- Building an SDK for Windows 111 ------------------------------ 112 113 Full Windows SDK builds are now only supported on Linux -- most of the 114 framework is not designed to be built on Windows so technically the Windows 115 SDK is build on top of a Linux SDK where a few binaries are replaced. So it 116 cannot be built on Windows, and it cannot be built on Mac, only on Linux. 117 118 I'll repeat this again because it's important: 119 120 To build the Android SDK for Windows, you need to use a *Linux* box. 121 122 123 A- Pre-requisites 124 ----------------- 125 126 Before you can even think of building the Android SDK for Windows, you need to 127 perform the steps from section "2- Building an SDK for MacOS and Linux" above: 128 setup and build a regular Linux SDK. Once this working, please continue here. 129 130 Under Ubuntu, you will need the following extra packages: 131 132 $ sudo apt-get install mingw32 tofrodos 133 134 mingw32 is the cross-compiler, tofrodos adds a unix2dos command 135 136 137 B- Building 138 ----------- 139 140 To build, perform the following steps: 141 142 $ . build/envsetup.sh 143 $ lunch sdk-eng 144 $ make win_sdk 145 146 Note that this will build both a Linux SDK then a Windows SDK. 147 The result is located at 148 out/host/windows/sdk/android-sdk_eng.${USER}_windows/ 149 150 151 152 ---------------------------- 153 4- Partial SDK Windows Tools 154 ---------------------------- 155 156 As explained above, you can only build a *full* SDK for Windows using Linux. 157 However sometimes you need to develop one specific tools, e.g. adb.exe or 158 aapt.exe, and it's just more convenient to do it on the same platform where 159 you can actually test it. This is what this section explains. 160 161 162 A- Cygwin pre-requisite & code checkout 163 --------------------------------------- 164 165 You must have Cygwin installed. You can use the latest Cygwin 1.7 or the 166 the "legacy Cygwin 1.5" from: 167 168 http://cygwin.org/ 169 170 Now configure it: 171 - When installing Cygwin, set Default Text File Type to Unix/binary, not DOS/text. 172 This is really important, otherwise you will get errors when trying to 173 checkout code using git. 174 - Packages that you must install or not: 175 - Required packages: autoconf, bison, curl, flex, gcc, g++, git, gnupg, make, 176 mingw-zlib, python, zip, unzip. 177 - Suggested extra packages: diffutils, emacs, openssh, rsync, vim, wget. 178 - Packages that must not be installed: readline. 179 180 Once you installed Cygwin properly, checkout the code from git as you did 181 for MacOS or Linux (see section 2 above.) 182 183 184 185 C- Building the Windows Tools 186 ----------------------------- 187 188 This is the easy part: run make on the tool you want. 189 How do you know which tools you can build? Well obviously all the ones 190 that come in an installed SDK/tools or SDK/platform-tools folder! 191 192 Example, to build adb: 193 194 $ cd ~/my-android-git 195 $ . build/envsetup.sh 196 $ lunch sdk-eng 197 $ make adb 198 199 The result will be somewhere in out/host/windows-x86/bin/. Just look at 200 the output from make to get the exact path. Since you are building this 201 under cygwin, you get an unstripped binary that you can happily feed to 202 gdb to get debugger symbols: 203 204 $ gdb --args out/host/windows-x86/bin/adb.exe <adb arguments> 205 206 207 And before you ask, msys is not supported, nor is MSVC or windbg. 208 209 So you can build a lot of little parts of the SDK on Windows, one tool 210 at a time, but not the full thing because basically building the whole 211 platform is not supported. This means you cannot build "android.jar" 212 nor "layoutlib.jar" under Windows. For this you want Linux. 213 214 215 216 D- Building the Windows Tools on Linux 217 -------------------------------------- 218 219 You can also build isolated windows tools directly on Linux. 220 Again, it requires a checkout of the full android code and the usual 221 setup like described above to build an SDK. 222 223 Then to build an isolated Windows binary, you'd do something like this: 224 225 $ cd ~/my-android-git 226 $ . build/envsetup.sh 227 $ lunch sdk-eng 228 $ USE_MINGW=1 make adb 229 230 The special environment variable "USE_MINGW" must be set to 1. This is 231 the clue to switch the make logic to cross-compiling to Windows under 232 Linux. 233 234 235 236 ------------------------------------- 237 4- Building an ADT plugin for Eclipse 238 ------------------------------------- 239 240 We've simplified the steps here. 241 It used to be that you'd have to download a specific version of 242 Eclipse and install it at a special location. That's not needed 243 anymore. 244 245 Instead you just change directories to your git repository and invoke the 246 build script by giving it a destination directory and an optional build number: 247 248 $ mkdir ~/mysdk 249 $ cd ~/my-android-git # <-- this is where you did your "repo sync" 250 $ sdk/eclipse/scripts/build_server.sh ~/mysdk $USER 251 252 253 The first argument is the destination directory. It must be absolute. Do not 254 give a relative destination directory such as "../mysdk" -- this would make the 255 Eclipse build fail with a cryptic message: 256 257 BUILD SUCCESSFUL 258 Total time: 1 minute 5 seconds 259 **** Package in ../mysdk 260 Error: Build failed to produce ../mysdk/android-eclipse 261 Aborting 262 263 The second argument is the build "number". The example used "$USER" but it 264 really is a free identifier of your choice. It cannot contain spaces nor 265 periods (dashes are ok.) If the build number is missing, a build timestamp will 266 be used instead in the filename. 267 268 The build should take something like 5-10 minutes. 269 270 271 When the build succeeds, you'll see something like this at the end of the 272 output: 273 274 ZIP of Update site available at ~/mysdk/android-eclipse-v200903272328.zip 275 or 276 ZIP of Update site available at ~/mysdk/android-eclipse-<buildnumber>.zip 277 278 When you load the plugin in Eclipse, its feature and plugin name will look like 279 "com.android.ide.eclipse.adt_0.9.0.v200903272328-<buildnumber>.jar". The 280 internal plugin ID is always composed of the package, the build timestamp and 281 then your own build identifier (a.k.a. the "build number"), if provided. This 282 means successive builds with the same build identifier are incremental and 283 Eclipse will know how to update to more recent ones. 284 285 286 287 ------------- 288 5- Conclusion 289 ------------- 290 291 This completes the howto guide on building your own SDK and ADT plugin. 292 Feedback is welcome on the public Android Open Source forums: 293 http://source.android.com/discuss 294 295 If you are upgrading from a pre-cupcake to a cupcake or later SDK please read 296 the accompanying document "howto_use_cupcake_sdk.txt". 297 298 -end- 299 300