2014-11-06 17:15:28 -08:00
|
|
|
page.title=Build System Overview
|
2014-03-17 11:24:24 -07:00
|
|
|
|
|
|
|
@jd:body
|
|
|
|
|
|
|
|
<div id="qv-wrapper">
|
|
|
|
<div id="qv">
|
|
|
|
<h2>In this document</h2>
|
|
|
|
<ol>
|
2014-11-06 17:15:28 -08:00
|
|
|
<li><a href="#detailed-build">A Detailed Look at the Build Process</a> </li>
|
2014-03-17 11:24:24 -07:00
|
|
|
</ol>
|
|
|
|
<h2>See also</h2>
|
|
|
|
<ul>
|
2014-11-06 17:15:28 -08:00
|
|
|
<li><a href="{@docRoot}sdk/installing/studio.html">
|
|
|
|
Getting Started with Android Studio</a></li>
|
|
|
|
<li><a href="{@docRoot}tools/studio/index.html">Android Studio Basics</a></li>
|
2014-12-08 11:28:16 -08:00
|
|
|
<li><a href="{@docRoot}sdk/installing/migrate.html">Migrating from Eclipse</a></li>
|
2014-03-17 11:24:24 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<a class="notice-developers-video" href="https://www.youtube.com/watch?v=LCJAgPkpmR0#t=504">
|
2014-03-17 11:24:24 -07:00
|
|
|
<div>
|
|
|
|
<h3>Video</h3>
|
2014-11-06 17:15:28 -08:00
|
|
|
<p>The New Android SDK Build System</p>
|
2014-03-17 11:24:24 -07:00
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<p>The Android build system is the toolkit you use to build, test, run and package
|
|
|
|
your apps. The build system can run as an integrated tool from the Android Studio menu and
|
|
|
|
independently from the command line. You can use the features of the build system to:</p>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>Customize, configure, and extend the build process.</li>
|
2014-11-06 17:15:28 -08:00
|
|
|
<li>Create multiple APKs for your app with different features using the same project and
|
|
|
|
modules.</li>
|
|
|
|
<li>Reuse code and resources across source sets.</li>
|
2014-03-17 11:24:24 -07:00
|
|
|
</ul>
|
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<p>The flexibility of the Android build system enables you to achieve all of this without
|
|
|
|
modifying your app's core source files. To build an Android Studio project, see
|
|
|
|
<a href="{@docRoot}tools/building/building-studio.html">Building and Running from Android Studio</a>.
|
|
|
|
To configure custom build settings in an Android Studio project, see
|
|
|
|
<a href="{@docRoot}tools/building/configuring-gradle.html">Configuring Gradle Builds</a>.</p>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<h2 id="detailed-build">A Detailed Look at the Build Process</h2>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<p>The build process involves many tools and processes that generate intermediate files on the
|
|
|
|
way to producing an <code>.apk</code>. If you are developing in Android Studio, the complete build
|
|
|
|
process is done every time you run the Gradle build task for your project or modules. The build
|
|
|
|
process is very flexible so it's useful, however, to understand what is happening under the hood
|
|
|
|
since much of the build process is configurable and extensible. The following diagram depicts the
|
|
|
|
different tools and processes that are involved in a build:</p>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<img src="{@docRoot}images/build.png" />
|
2014-03-17 11:24:24 -07:00
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<p>The general process for a typical build is outlined below. The build system merges all the
|
|
|
|
resources from the configured product flavors, build types, and dependencies. If different
|
|
|
|
folders contain resources with the same name or setting, the following override priority order is:
|
|
|
|
dependencies override build types, which override product flavors, which override the main source
|
|
|
|
directory.</p>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<ul>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<li>The Android Asset Packaging Tool (aapt) takes your application resource files, such as the
|
|
|
|
<code>AndroidManifest.xml</code> file and the XML files for your Activities, and compiles them.
|
|
|
|
An <code>R.java</code> is also produced so you can reference your resources from your Java code.</li>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<li>The aidl tool converts any <code>.aidl</code> interfaces that you have into Java interfaces.</li>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<li>All of your Java code, including the <code>R.java</code> and <code>.aidl</code> files, are
|
|
|
|
compiled by the Java compiler and .class files are output.</li>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<li>The dex tool converts the .class files to Dalvik byte code. Any 3rd party libraries and
|
|
|
|
.class files that you have included in your module build are also converted into <code>.dex</code>
|
|
|
|
files so that they can be packaged into the final <code>.apk</code> file.</li>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<li>All non-compiled resources (such as images), compiled resources, and the .dex files are
|
|
|
|
sent to the apkbuilder tool to be packaged into an <code>.apk</code> file.</li>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<li>Once the <code>.apk</code> is built, it must be signed with either a debug or release key
|
|
|
|
before it can be installed to a device.</li>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<li>Finally, if the application is being signed in release mode, you must align the
|
|
|
|
<code>.apk</code> with the zipalign tool. Aligning the final <code>.apk</code> decreases memory
|
|
|
|
usage when the application is -running on a device.</li>
|
|
|
|
</ul>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<p class="note"><b>Note:</b> Apps are limited to a 64K method reference limit. If your app reaches
|
|
|
|
this limit, the build process outputs the following error message:
|
2014-03-17 11:24:24 -07:00
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<pre>Unable to execute dex: method ID not in [0, 0xffff]: 65536.</pre>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
To avoid this error, see
|
|
|
|
<a href="{@docRoot}tools/building/multidex.html">Building Apps with Over 65K Methods</a>.
|
|
|
|
</p>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<h3>Build output</h3>
|
2014-03-17 11:24:24 -07:00
|
|
|
|
2014-11-06 17:15:28 -08:00
|
|
|
<p>The build generates an APK for each build variant in the <code>app/build</code> folder:
|
2014-12-17 17:25:02 -08:00
|
|
|
the <code>app/build/outputs/apk/</code> directory contains packages named
|
2014-03-17 11:24:24 -07:00
|
|
|
<code>app-<flavor>-<buildtype>.apk</code>; for example, <code>app-full-release.apk</code> and
|
|
|
|
<code>app-demo-debug.apk</code>.</p>
|
|
|
|
|
|
|
|
|