blob: 3e56569dbeaaa4d36224baa48d140a0dfacc5bf3 [file] [log] [blame]
Raphael Molle3721362010-06-23 15:58:16 -07001Copyright (C) 2009 The Android Open Source Project
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14
15
16Subject: How to build an Android SDK & ADT Eclipse plugin.
17Date: 2009/03/27
Raphael Molld4ce67a2013-04-09 12:37:36 -070018Updated: 2013/04/09
Raphael Molle3721362010-06-23 15:58:16 -070019
20
21Table 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----------
320- 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-----------
521- Foreword
53-----------
54
55This document explains how to build the Android SDK and the ADT Eclipse plugin.
56
57It is designed for advanced users which are proficient with command-line
58operations and know how to setup the pre-required software.
59
60Basically it's not trivial yet when done right it's not that complicated.
61
62
63
64--------------------------------------
652- Building an SDK for MacOS and Linux
66--------------------------------------
67
68First, setup your development environment and get the Android source code from
69git as explained here:
70
Chris Peterson963b3ce2010-06-25 17:32:29 -070071 http://source.android.com/source/download.html
Raphael Molle3721362010-06-23 15:58:16 -070072
73For example for the cupcake branch:
74
75 $ mkdir ~/my-android-git
76 $ cd ~/my-android-git
Raphael Molld4ce67a2013-04-09 12:37:36 -070077 $ repo init -u https://android.googlesource.com/platform/manifest -b master -g all,-notdefault,tools
Raphael Molle3721362010-06-23 15:58:16 -070078 $ repo sync
79
80Then 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
87This will take a while, maybe between 20 minutes and several hours depending on
88your 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
92Some 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------------------------------
1103- Building an SDK for Windows
111------------------------------
112
Raphael Molld4ce67a2013-04-09 12:37:36 -0700113Full Windows SDK builds are now only supported on Linux -- most of the
114framework is not designed to be built on Windows so technically the Windows
115SDK is build on top of a Linux SDK where a few binaries are replaced. So it
116cannot be built on Windows, and it cannot be built on Mac, only on Linux.
Raphael Molle3721362010-06-23 15:58:16 -0700117
Raphaelf8213532011-11-28 16:37:07 -0800118I'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
Raphael Molld4ce67a2013-04-09 12:37:36 -0700122
Raphaelf8213532011-11-28 16:37:07 -0800123A- Pre-requisites
124-----------------
125
126Before you can even think of building the Android SDK for Windows, you need to
127perform the steps from section "2- Building an SDK for MacOS and Linux" above:
128setup and build a regular Linux SDK. Once this working, please continue here.
129
Raphael Molld4ce67a2013-04-09 12:37:36 -0700130Under Ubuntu, you will need the following extra packages:
Raphaelf8213532011-11-28 16:37:07 -0800131
132$ sudo apt-get install mingw32 tofrodos
133
134mingw32 is the cross-compiler, tofrodos adds a unix2dos command
135
136
137B- Building
138-----------
139
140To build, perform the following steps:
141
142$ . build/envsetup.sh
143$ lunch sdk-eng
144$ make win_sdk
145
Raphael Molld4ce67a2013-04-09 12:37:36 -0700146Note that this will build both a Linux SDK then a Windows SDK.
147The result is located at
Raphaelf8213532011-11-28 16:37:07 -0800148 out/host/windows/sdk/android-sdk_eng.${USER}_windows/
Raphael Molle3721362010-06-23 15:58:16 -0700149
150
151
Raphaelf8213532011-11-28 16:37:07 -0800152----------------------------
1534- Partial SDK Windows Tools
154----------------------------
155
156As explained above, you can only build a *full* SDK for Windows using Linux.
157However sometimes you need to develop one specific tools, e.g. adb.exe or
158aapt.exe, and it's just more convenient to do it on the same platform where
159you can actually test it. This is what this section explains.
160
Raphael Molld4ce67a2013-04-09 12:37:36 -0700161
Raphaelf8213532011-11-28 16:37:07 -0800162A- Cygwin pre-requisite & code checkout
Raphael Molle3721362010-06-23 15:58:16 -0700163---------------------------------------
164
Raphaelf8213532011-11-28 16:37:07 -0800165You must have Cygwin installed. You can use the latest Cygwin 1.7 or the
166the "legacy Cygwin 1.5" from:
Raphael Molle3721362010-06-23 15:58:16 -0700167
Raphaelf8213532011-11-28 16:37:07 -0800168 http://cygwin.org/
Raphael Molle3721362010-06-23 15:58:16 -0700169
Raphael Molle3721362010-06-23 15:58:16 -0700170Now 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
180Once you installed Cygwin properly, checkout the code from git as you did
Raphaelf8213532011-11-28 16:37:07 -0800181for MacOS or Linux (see section 2 above.)
Raphael Molle3721362010-06-23 15:58:16 -0700182
Raphaelf8213532011-11-28 16:37:07 -0800183
184
185C- Building the Windows Tools
186-----------------------------
187
188This is the easy part: run make on the tool you want.
189How do you know which tools you can build? Well obviously all the ones
190that come in an installed SDK/tools or SDK/platform-tools folder!
191
192Example, to build adb:
193
Raphael Molle3721362010-06-23 15:58:16 -0700194 $ cd ~/my-android-git
Raphaelf8213532011-11-28 16:37:07 -0800195 $ . build/envsetup.sh
196 $ lunch sdk-eng
197 $ make adb
198
199The result will be somewhere in out/host/windows-x86/bin/. Just look at
200the output from make to get the exact path. Since you are building this
201under cygwin, you get an unstripped binary that you can happily feed to
202gdb to get debugger symbols:
203
204 $ gdb --args out/host/windows-x86/bin/adb.exe <adb arguments>
205
206
207And before you ask, msys is not supported, nor is MSVC or windbg.
208
209So you can build a lot of little parts of the SDK on Windows, one tool
210at a time, but not the full thing because basically building the whole
211platform is not supported. This means you cannot build "android.jar"
212nor "layoutlib.jar" under Windows. For this you want Linux.
Raphael Molle3721362010-06-23 15:58:16 -0700213
214
215
Raphaelf8213532011-11-28 16:37:07 -0800216D- Building the Windows Tools on Linux
217--------------------------------------
Raphael Molle3721362010-06-23 15:58:16 -0700218
Raphaelf8213532011-11-28 16:37:07 -0800219You can also build isolated windows tools directly on Linux.
220Again, it requires a checkout of the full android code and the usual
221setup like described above to build an SDK.
Raphael Molle3721362010-06-23 15:58:16 -0700222
Raphaelf8213532011-11-28 16:37:07 -0800223Then to build an isolated Windows binary, you'd do something like this:
Raphael Molld4ce67a2013-04-09 12:37:36 -0700224
Raphael Molle3721362010-06-23 15:58:16 -0700225 $ cd ~/my-android-git
Raphaelf8213532011-11-28 16:37:07 -0800226 $ . build/envsetup.sh
227 $ lunch sdk-eng
228 $ USE_MINGW=1 make adb
Raphael Molle3721362010-06-23 15:58:16 -0700229
Raphaelf8213532011-11-28 16:37:07 -0800230The special environment variable "USE_MINGW" must be set to 1. This is
231the clue to switch the make logic to cross-compiling to Windows under
232Linux.
Raphael Molle3721362010-06-23 15:58:16 -0700233
234
235
236-------------------------------------
2374- Building an ADT plugin for Eclipse
238-------------------------------------
239
Raphael Molld4ce67a2013-04-09 12:37:36 -0700240We've simplified the steps here.
241It used to be that you'd have to download a specific version of
242Eclipse and install it at a special location. That's not needed
243anymore.
Raphael Molle3721362010-06-23 15:58:16 -0700244
Raphael Molld4ce67a2013-04-09 12:37:36 -0700245Instead you just change directories to your git repository and invoke the
246build script by giving it a destination directory and an optional build number:
Raphael Molle3721362010-06-23 15:58:16 -0700247
248 $ mkdir ~/mysdk
249 $ cd ~/my-android-git # <-- this is where you did your "repo sync"
Raphaelf8213532011-11-28 16:37:07 -0800250 $ sdk/eclipse/scripts/build_server.sh ~/mysdk $USER
Raphael Molle3721362010-06-23 15:58:16 -0700251
Raphael Molld4ce67a2013-04-09 12:37:36 -0700252
Raphael Molle3721362010-06-23 15:58:16 -0700253The first argument is the destination directory. It must be absolute. Do not
Raphael Molld4ce67a2013-04-09 12:37:36 -0700254give a relative destination directory such as "../mysdk" -- this would make the
Raphael Molle3721362010-06-23 15:58:16 -0700255Eclipse 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
263The second argument is the build "number". The example used "$USER" but it
264really is a free identifier of your choice. It cannot contain spaces nor
265periods (dashes are ok.) If the build number is missing, a build timestamp will
266be used instead in the filename.
267
268The build should take something like 5-10 minutes.
269
270
271When the build succeeds, you'll see something like this at the end of the
272output:
273
274 ZIP of Update site available at ~/mysdk/android-eclipse-v200903272328.zip
275or
276 ZIP of Update site available at ~/mysdk/android-eclipse-<buildnumber>.zip
277
278When 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
280internal plugin ID is always composed of the package, the build timestamp and
281then your own build identifier (a.k.a. the "build number"), if provided. This
282means successive builds with the same build identifier are incremental and
283Eclipse will know how to update to more recent ones.
284
285
286
287-------------
2885- Conclusion
289-------------
290
291This completes the howto guide on building your own SDK and ADT plugin.
292Feedback is welcome on the public Android Open Source forums:
293 http://source.android.com/discuss
294
295If you are upgrading from a pre-cupcake to a cupcake or later SDK please read
296the accompanying document "howto_use_cupcake_sdk.txt".
297
298-end-
299