blob: 32e1c3e5402946886e511fc1754e2ae8862d94d9 [file] [log] [blame]
The Android Open Source Project5c118522008-10-21 07:00:00 -07001
2<html>
3<head>
4<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
5<title>Android - Build System</title>
6<script src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0&amp;key=internal-codesite" type="text/javascript"></script>
7<script src="http://code.google.com/js/jquery.js" type="text/javascript"></script>
8<script type="text/javascript">var _tocPath_ = 'http://code.google.com/android/_toc.ezt';</script>
9<script src="http://code.google.com/js/codesite.pack.01312008.js" type="text/javascript"></script>
10<link href="http://code.google.com/css/codesite.pack.01312008.css" type="text/css" rel="stylesheet">
11</link>
12
13<!--[if IE]><link rel="stylesheet" type="text/css" href="/css/iehacks.css" /><![endif]-->
14<script src="http://code.google.com/android/assets/search_autocomplete.js"></script>
15<link rel="stylesheet" type="text/css" href="http://code.google.com/css/semantic_headers.css" />
16<link rel="stylesheet" type="text/css" href="http://code.google.com/android/assets/style.css" />
17<script>
18 jQuery(document).ready(function() {
19 jQuery("pre").addClass("prettyprint");
20 });
21 </script>
22<style type="text/css">
23<!--
24h1,h2,h3 {
25 color: #000000;
26}
27-->
28</style>
29</head>
30<body class="gc-documentation">
31<div id="gc-container">
32<a name="top"></a>
33<div id="skipto"> </div>
34<div id="langpref">
35 <!--<a class="dropdown" href="/">English</a> <span>|</span> <a href="/more/">Site Directory</a> -->
36</div>
37<div id="gc-header">
38 <div id="logo"><a href="http://code.google.com/android/index.html"><img src="http://code.google.com/android/images/logo_android.gif" alt="Android"/></a></div>
39 <div id="search" style="inline">
40 <div id="searchForm" class="searchForm" style="height: 44px;">
41 <!--previously form was here-->
42 </div>
43 <!-- end searchForm -->
44 <noscript>
45 <style type="text/css">
46 .searchForm {
47 display : none !important;
48 }
49 .searchForm2 {
50 display : inline !important;
51 }
52 </style>
53 </noscript>
54 <div id="searchForm2" class="searchForm2" style="display:none">
55 <form id="searchbox_001456098540849067467:6whlsytkdqg" action="http://www.google.com/cse">
56 <input type="hidden" name="cx" value="001456098540849067467:6whlsytkdqg" />
57 <input type="hidden" name="cof" value="FORID:0" />
58 <input type="text" name="q" maxlength="2048" size="41" autocomplete="off" title="Google Code Search"/>
59 <input type="submit" name="sa" value="Search" title="Search"/>
60 <br/>
61 <div class="greytext">e.g. "ajax apis" or "open source"</div>
62 </form>
63 </div>
64 <!-- end searchForm2 -->
65 </div>
66 <!-- end search -->
67</div>
68<!-- end gc-header -->
69<div id="searchControl" class="search-control"></div>
70<!--[if IE]><iframe id="backiFrame" name="backiFrame" src='/dummy.html' style="display:none"></iframe><![endif]-->
71<div id="codesiteContent">
72<a name="gc-topnav-anchor"></a>
73<div id="gc-topnav">
74 <h1>Android Platform Development Kit</h1>
75 <ul class="gc-topnav-tabs">
76 <li id="sdk_link"> <a href="http://code.google.com/android/index.html" title="Android Software Development Kit">SDK</a> </li>
77 <li id="docs_link"> <a href="index.html" title="Official Android documentation">Docs</a> </li>
78 <li id="faq_link"> <a href="http://code.google.com/android/kb/index.html" title="Answers to frequently asked questions about Android">FAQ</a> </li>
79 <li> <a href="http://android-developers.blogspot.com/" title="Official Android blog">Blog</a> </li>
80 <li> <a href="http://code.google.com/android/groups.html" title="Android developer forum">Group</a> </li>
81 <li> <a href="http://code.google.com/android/terms.html" title="Android terms of service">Terms</a> </li>
82 <li> <a href="mailto:android-pdk-feedback@google.com?subject=PDK%20Feedback&body=(filed%20from:%20build_system.html%20v0.3%20-%209%20June%202008)%0D%0A%0D%0ASUMMARY:%0D%0A%0D%0A%0D%0A%0D%0ASTEPS%20TO%20REPRODUCE:%0D%0A%0D%0A%0D%0A%0D%0AADDITIONAL%20NOTES:">Report a Problem</a> </li>
83 </ul>
84</div>
85<!-- end gc-topnav -->
86<div class="g-section g-tpl-180">
87<a name="gc-toc"></a>
88<div class="g-unit g-first" id="gc-toc">
89 <ul>
90 <li>
91 <h1><a href="index.html">Documentation</a></h1>
92 <ul>
93 <li> <strong>Introduction</strong>
94 <ul>
95 <li><a href="system_requirements.html">Device Requirements</a></li>
96 </ul>
97 </li>
98 <li> <strong>Dev Environment Setup</strong>
99 <ul>
100 <li><a href="source_setup_guide.html">Host System Setup</a></li>
101 <li><a href="getting_source_code.html">Getting Source Code</a></li>
102 <li> <a href="intro_source_code.html">Source Code Overview</a></li>
103 <li><a href="build_system.html">Build System</a></li>
104 </ul>
105 </li>
106 <li> <strong>Basic Bring up</strong>
107 <ul>
108 <li><a href="build_new_device.html">Building New Device</a></li>
109 <li><a href="bring_up.html">Bring up</a></li>
110 <li><a href="keymaps_keyboard_input.html">Keymaps and Keyboard</a></li>
111 <li><a href="display_drivers.html">Display Drivers</a></li>
112 </ul>
113 </li>
114 <li> <strong>Multimedia</strong>
115 <ul>
116 <li><a href="audio_sub_system.html">Audio Subsystem</a></li>
117 </ul>
118 </li>
119 <li> <strong>Power Management</strong>
120 <ul>
121 <li><a href="power_management.html">Power Management</a></li>
122 </ul>
123 </li>
124 <li> <strong>Telephony</strong>
125 <ul>
126 <li><a href="telephony.html">Radio Interface Layer</a></li>
127 </ul>
128 </li>
129 <li> <strong>Testing</strong>
130 <ul>
131 <li><a href="instrumentation_framework.html">Instrumentation Framework</a></li>
132 <li><a href="instrumentation_testing.html">Instrumentation Testing</a></li>
133 </ul>
134 </li>
135 </ul>
136 </li>
137 </ul>
138</div>
139<a name="gc-pagecontent"></a>
140<div class="g-unit" id="gc-pagecontent">
141<div id="jd-content">
142<div class="jd-descr">
143
144
145<a name="androidBuildSystemTitle"></a><h1>Android Build System</h1>
146
147
148
149<a name="toc"/>
150<div style="padding:10px">
151<a href="#androidBuildSystemIntroduction">Introduction</a><br/>
152<a href="#androidBuildSystemUnderstanding">Understanding Android's Build System</a><br/><div style="padding-left:40px">
153
154<a href="#androidBuildSystemOverview">Understanding the makefile</a><br/>
155<a href="#androidBuildSystemLayers">Layers</a><br/>
156<a href="#androidBuildSystemProductDefFiles">Product Definition Files</a><br/></div>
157<a href="#androidSourceSetupBuildingCodeBase">Building the Android Platform</a><br/><div style="padding-left:40px">
158
159<a href="#androidSourceSetupBuildingDeviceCodeBase">Device Code</a><br/>
160<a href="#androidBuildingCleaning">Cleaning Up</a><br/>
161<a href="#androidBuildingSpeeding">Speeding Up Rebuilds</a><br/>
162<a href="#androidBuildingTroubleshooting">Troubleshooting</a><br/></div>
163<a href="#androidSourceSetupBuildingKernel">Building the Android Kernel</a><br/><div style="padding-left:40px">
164
165<a href="#androidSourceSetupBuildingKernelCheckingBranch">Checking Out a Branch</a><br/>
166<a href="#androidSourceSetupBuildingKernelBranchLocation">Verifying Location</a><br/>
167<a href="#androidSourceSetupBuildingKernelBuild">Building the Kernel</a><br/></div></div></font></div>
168
169<a name="androidBuildSystemIntroduction"></a><h2>Introduction</h2>
170
171<p>Android uses a custom build system to generate tools, binaries, and documentation. This document provides an overview of Android's build system and instructions for doing a simple build. </p>
172<p>Android's build system is make based and requires a recent version of GNU Make (note that Android uses advanced features of GNU Make that may not yet appear on the GNU Make web site). Before continuing, check your version of make by running <code>% make -v</code>. If you don't have version 3.80 or greater, you need to <a href="http://www.gnu.org/software/make/">upgrade your version of make</a>. </p>
173
174
175<a name="androidBuildSystemUnderstanding"></a><h2>Understanding Android's Build System</h2>
176
177
178
179<a name="androidBuildSystemOverview"></a><h3>Understanding the makefile</h3>
180
181<p>A makefile defines how to build a particular application. Makefiles typically include all of the following elements:</p>
182<ol>
183 <li>Name: Give your build a name (<code>LOCAL_MODULE := &lt;build_name&gt;</code>).</li>
184 <li>Local Variables: Clear local variables with CLEAR_VARS (<code>include $(CLEAR_VARS)</code>).</li>
185 <li>Files: Determine which files your application depends upon (<code>LOCAL_SRC_FILES := main.c</code>).</li>
186 <li>Tags: Define tags, as necessary (<code>LOCAL_MODULE_TAGS := eng development</code>).</li>
187 <li>Libraries: Define whether your application links with other libraries (<code>LOCAL_SHARED_LIBRARIES := cutils</code>).</li>
188 <li>Template file: Include a template file to define underlining make tools for a particular target (<code>include $(BUILD_EXECUTABLE)</code>).</li>
189</ol>
190
191<p>The following snippet illustrates a typical makefile.</p>
192<pre class="prettyprint">
193LOCAL_PATH := $(my-dir)
194include $(CLEAR_VARS)
195LOCAL_MODULE := &lt;buil_name&gt;
196LOCAL_SRC_FILES := main.c
197LOCAL_MODULE_TAGS := eng development
198LOCAL_SHARED_LIBRARIES := cutils
199include $(BUILD_EXECUTABLE)
200(HOST_)EXECUTABLE, (HOST_)JAVA_LIBRARY, (HOST_)PREBUILT, (HOST_)SHARED_LIBRARY,
201 (HOST_)STATIC_LIBRARY, PACKAGE, JAVADOC, RAW_EXECUTABLE, RAW_STATIC_LIBRARY,
202 COPY_HEADERS, KEY_CHAR_MAP
203</pre>
204<p>The snippet above includes artificial line breaks to maintain a print-friendly document.</p>
205
206
207<a name="androidBuildSystemLayers"></a><h3>Layers</h3>
208
209<p>The build hierarchy includes the abstraction layers described in the table below.</p>
210
211<p>Each layer relates to the one above it in a one-to-many relationship. For example, an arch can have more than one board and each board can have more than one device. You may define an element in a given layer as a specialization of an element in the same layer, thus eliminating copying and simplifying maintenance.</p>
212
213<table border=1 cellpadding=2 cellspacing=0>
214 <tbody><tr>
215 <th scope="col">Layer</th>
216 <th scope="col">Example</th>
217 <th scope="col">Description</th>
218 </tr>
219 <tr>
220 <td valign="top">Product</td>
221 <td valign="top">myProduct, myProduct_eu, myProduct_eu_fr, j2, sdk</td>
222 <td valign="top">The product layer defines a complete specification of a shipping product, defining which modules to build and how to configure them. You might offer a device in several different versions based on locale, for example, or on features such as a camera. </td>
223 </tr>
224 <tr>
225 <td valign="top">Device</td>
226 <td valign="top">myDevice, myDevice_eu, myDevice_eu_lite</td>
227 <td valign="top">The device layer represents the physical layer of plastic on the device. For example, North American devices probably include QWERTY keyboards whereas devices sold in France probably include AZERTY keyboards. Peripherals typically connect to the device layer. </td>
228 </tr>
229 <tr>
230 <td valign="top">Board</td>
231 <td valign="top">sardine, trout, goldfish </td>
232 <td valign="top">The board layer represents the bare schematics of a product. You may still connect peripherals to the board layer. </td>
233 </tr>
234 <tr>
235 <td valign="top">Arch</td>
236 <td valign="top">arm (arm5te) (arm6), x86, 68k </td>
237 <td valign="top">The arch layer describes the processor running on your board. </td>
238 </tr>
239</table>
240
241
242<a name="androidBuildSystemProductDefFiles"></a><h3>Product Definition Files</h3>
243
244<p>Product-specific variables are defined in product definition files. A product definition file can inherit from other product definition files, thus reducing the need to copy and simplifying maintenance.</p>
245<p>Variables maintained in a product definition files include:</p>
246<p><ul>
247<li><code>PRODUCT_DEVICE</code></LI>
248<LI><code>LOCALES</code></LI>
249<LI><code>BRANDING_PARTNER</code></LI>
250<LI><code>PROPERTY_OVERRIDES</code></LI>
251</UL>
252</P>
253<p>The snippet below illustrates a typical product definition file.</p>
254<PRE class="prettyprint">
255//device/target/product/core.mk
256PRODUCT_PACKAGES := Home SettingsProvider ...
257//device/target/product/generic.mk
258PRODUCT_PACKAGES := Calendar Camera SyncProvider ...
259$(call inherit-product, target/product/core.mk)
260PRODUCT_NAME := generic
261//device/partner/google/products/core.mk
262PRODUCT_PACKAGES := Maps GoogleAppsProvider ...
263$(call inherit-product, target/product/core.mk)
264//device/partner/google/products/generic.mk
265PRODUCT_PACKAGES := Gmail GmailProvider ...
266$(call inherit-product, partner/google/products/core.mk)
267$(call inherit-product, target/product/generic.mk)
268PRODUCT_NAME := google_generic
269
270</pre>
271
272
273<a name="androidSourceSetupBuildingCodeBase"></a><h2>Building the Android Platform</h2>
274
275<p>This section describes how to build the default version of Android. Once you are comfortable with a generic build, then you can begin to modify Android for your own target device.</p>
276
277
278<a name="androidSourceSetupBuildingDeviceCodeBase"></a><h3>Device Code</h3>
279
280<p>Of the two options below, the first tends to yield more consistent results.</p>
281
282
283<a name="androidSourceSetupBuildingDeviceCodeBaseOption2"></a><h4>Option 1</h4>
284
285<p>Create a local version of buildspec.mk. The easiest way to do so is to change to your device directory and execute the following:</p>
286<pre class="prettyprint">% cp buildspec.mk.default buildspec.mk ; chmod u=rw buildspec.mk</pre>
287<p>The default <code>buildspec.mk</code>. file is written so that all options appear commented. In order to establish a personal configuration environment, edit <code>buildspec.mk</code> as desired.</p>
288<p>Once you have established your configuration environment, you can build the device code base by executing make in order to build the Android binaries. This may take a long time the first time you issue this command. On a dual-core machine, consider using '-j2' (or even '-j4') to speed up the build.</p>
289<pre class="prettyprint">% make -j2</pre>
290
291
292<a name="androidSourceSetupBuildingDeviceCodeBaseOption1"></a><h4>Option 2</h4>
293
294<p>To do a generic build of android, source <code>//device/envsetup.sh</code>, which contains necessary variable and function definitions, as described below.</p>
295<pre class="prettyprint">
296% cd $TOP
297
298% . envsetup.sh
299
300% partner_setup generic
301 //select generic as the product
302
303% make -j4 PRODUCT-generic-user
304</pre>
305<p>You can also replace user with eng for a debug engineering build:</p>
306
307<pre class="prettyprint">
308% make -j4 PRODUCT-generic-eng
309</pre>
310
311
312<a name="androidBuildingCleaning"></a><h3>Cleaning Up</h3>
313
314<p>Execute <code>% m clean</code> to clean up the binaries you just created. You can also execute <code>% m clobber</code> to get rid of the binaries of all combos. <code>% m clobber</code> is equivalent to removing the <code>//device/out/</code> directory where all generated files are stored.</p>
315
316
317<a name="androidBuildingSpeeding"></a><h3>Speeding Up Rebuilds</h3>
318
319<p> The binaries of each combo are stored as distinct sub-directories of <code>//device/out/</code>, making it possible to quickly switch between combos without having to recompile all sources each time. </p>
320<p> However, performing a clean rebuild is necessary if the build system doesn't catch changes to environment variables or makefiles. If this happens often, you should define the <code>USE_CCACHE</code> environment variable as shown below: </p>
321<pre class="prettyprint">
322% export USE_CCACHE=1
323</pre>
324<p>Doing so will force the build system to use the ccache compiler cache tool, which reduces recompiling all sources.</p>
325
326<p><code>ccache</code> binaries are provided in <code>//device/prebuilt/...</code> and don't need to get installed on your system.</p>
327
328
329<a name="androidBuildingTroubleshooting"></a><h3>Troubleshooting</h3>
330
331<p>The following error is likely caused by running an outdated version of Java.</p>
332<pre class="prettyprint">
333device Dex: core UNEXPECTED TOP-LEVEL ERROR:
334java.lang.NoSuchMethodError: method java.util.Arrays.hashCode with
335signature ([Ljava.lang.Object;)I was not found.
336 at com.google.util.FixedSizeList.hashCode(FixedSizeList.java:66)
337 at com.google.rop.code.Rop.hashCode(Rop.java:245)
338 at java.util.HashMap.hash(libgcj.so.7)
339[...]
340</pre>
341<p><code>dx</code> is a Java program that uses facilities first made available in Java version 1.5. Check your version of Java by executing <code>% java -version</code> in the shell you use to build. You should see something like:</p>
342<pre class="prettyprint">
343java version "1.5.0_07"
344Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-164)
345Java HotSpot(TM) Client VM (build 1.5.0_07-87, mixed mode, sharing)
346</pre>
347<p>If you do have Java 1.5 or later and your receive this error, verify that you have properly updated your <code>PATH</code> variable.</p>
348
349
350<a name="androidSourceSetupBuildingKernel"></a><h2>Building the Android Kernel</h2>
351
352<p>This section describes how to build Android's default kernel. Once you are comfortable with a generic build, then you can begin to modify Android drivers for your own target device.</p>
353
354
355<p>To build the kernel base, switch to the device directory (<code>/home/joe/android/device</code>) in order to establish variables and run:
356<pre class="prettyprint">
357% . envsetup.sh
358% partner_setup generic
359</pre>
360<p>Then switch to the kernel directory <code>/home/joe/android/kernel</code>.
361
362
363<a name="androidSourceSetupBuildingKernelCheckingBranch"></a><h3>Checking Out a Branch</h3>
364
365<p>The default branch is always <code>android</code>. To check out a different branch, execute the following:</p>
366
367<pre class="prettyprint">
368% git checkout --track -b android-mydevice origin/android-mydevice
369 //Branch android-mydevice set up to track remote branch
370% refs/remotes/origin/android-mydevice.
371 //Switched to a new branch "android-mydevice"
372</pre>
373
374<p>To simplify code management, give your local branch the same name as the remote branch it is tracking (as illustrated in the snippet above). Switch between branches by executing <code>% git checkout &lt;branchname&gt;</code>.</p>
375
376
377<a name="androidSourceSetupBuildingKernelBranchLocation"></a><h3>Verifying Location</h3>
378
379<p>Find out which branches exist (both locally and remotely) and which one is active (marked with an asterisk) by executing the following:</p>
380<pre class="prettyprint">
381% git branch -a
382 android
383* android-mydevice
384 origin/HEAD
385 origin/android
386 origin/android-mydevice
387 origin/android-mychipset
388</pre>
389<p>To only see local branches, omit the <code>-a</code> flag.</p>
390
391
392<a name="androidSourceSetupBuildingKernelBuild"></a><h3>Building the Kernel</h3>
393
394<p>To build the kernel, execute:</p>
395<pre class="prettyprint">
396% make -j4
397</pre>
398
399
400<p><span class="lh2"><a name="androidFooter"></a></span>
401
402 </div>
403 </div>
404 <!-- end gc-pagecontent -->
405 </div>
406 <!-- end gooey wrapper -->
407 </div>
408 <!-- end codesearchresults -->
409 <div id="gc-footer" dir="ltr">
410 <div class="text"> &copy;2008 Google<!-- - <a href="/">Code Home</a> - <a href="http://www.google.com/accounts/TOS">Site Terms of Service</a> - <a href="http://www.google.com/privacy.html">Privacy Policy</a> - <a href="/more">Site Directory</a> --></div>
411 </div>
412 <!-- end gc-footer -->
413</div>
414<!-- end gc-containter -->
415<script src="http://www.google-analytics.com/ga.js" type="text/javascript">
416</script>
417<script type="text/javascript">
418 try {
419 var pageTracker = _gat._getTracker("UA-18071-1");
420 pageTracker._setAllowAnchor(true);
421 pageTracker._initData();
422 pageTracker._trackPageview();
423 } catch(e) {}
424</script>
425<div id="jd-build-id"> v0.3 - 9 June 2008</div>
426</div></div></div></body>
427</html>
428