am fa5f184f: docs: studio migration guide

* commit 'fa5f184faf7da28e3a6d2acd18bb9bfaac4eb2f1':
  docs: studio migration guide
This commit is contained in:
Rich Slogar
2015-06-26 05:39:31 +00:00
committed by Android Git Automerger
11 changed files with 1030 additions and 104 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@@ -4,53 +4,264 @@ page.title=Migrating to Android Studio
<div id="qv-wrapper">
<div id="qv">
<h2>In this document</h2>
<ol>
<li><a href="#overview">Migration Overview</a></li>
<li><a href="#prerequisites">Migration Prerequisites</a></li>
<li><a href="#migrate">Importing Projects to Android Studio</a></li>
<li><a href="#post-migration">Validating imported projects</a></li>
</ol>
<h2>See also</h2>
<ul>
<li><a href="{@docRoot}tools/studio/eclipse-transition-guide.html">
Transition Guide for Eclipse ADT</a></li>
<li><a href="http://confluence.jetbrains.com/display/IntelliJIDEA/FAQ+on+Migrating+to+IntelliJ+IDEA"
class="external-link">IntelliJ FAQ on migrating to IntelliJ IDEA</a></li>
<li><a href="http://confluence.jetbrains.com/display/IntelliJIDEA/Working+in+Eclipse+Compatibility+Mode" class="external-link"
>Eclipse Compatibility Mode</a></li>
<li><a href="http://confluence.jetbrains.com/display/IntelliJIDEA/FAQ+on+Migrating+to+IntelliJ+IDEA" class="external-link"
>FAQ on Migrating</a></li>
class="external-link">IntelliJ FAQ on migrating to IntelliJ IDEA</a></li>
<li><a href="http://confluence.jetbrains.com/display/IntelliJIDEA/IntelliJ+IDEA+for+Eclipse+Users"
class="external-link">IntelliJ IDEA for Eclipse users</a></li>
<li><a href="{@docRoot}tools/studio/index.html">Android Studio Overview</a></li>
</ul>
</div>
</div>
<p>If you have been using <a href="{@docRoot}tools/help/adt.html">Eclipse with ADT</a>, be aware
that <a href="{@docRoot}tools/studio/index.html">Android Studio</a> is now the official IDE for
Android, so you should migrate to Android Studio to receive all the latest IDE updates.</p>
<p>Migrating from Eclipse ADT to Android Studio requires adapting to a new project structure,
build system, and IDE functionality. To simplify the migration process, Android Studio provides an
import tool so you can quickly transition your Eclipse ADT workspaces and Ant build scripts to
Android Studio projects and <a href="http://www.gradle.org">Gradle</a>-based build files.</p>
<p>To migrate existing Android projects, simply import them using Android Studio:</p>
<p>This document provides an overview of the migration process and walks you
through a sample import procedure. For more information about Android Studio features and the
Gradle-based build system, see <a href="{@docRoot}tools/studio/index.html">Android Studio Overview</a>
and <a href="{@docRoot}tools/building/configuring-gradle.html">Configuring Gradle Builds</a>.</p>
<h2 id="overview">Migration Overview </h2>
<p>Migrating from Eclipse to Android Studio requires that you change the structure of your
development projects, move to a new build system, and use a new user interface. Here are some of
the key changes you should be aware of as you prepare to migrate to Android Studio:</p>
<ul>
<li><strong>Project files</strong>
<p>Android Studio uses a different project structure. Each Eclipse ADT
project is called a module in Android Studio. Each instance of Android
Studio contains a project with one or more app modules. For more information see,
<a href="{@docRoot}tools/studio/eclipse-migration-guide.html#project-structure">Project
Structure</a>.</p></li>
<li><strong>Manifest settings</strong>
<p>Several elements in the <code>AndroidManifest.xml</code> file are now properties in the
<code>defaultConfig</code> and <code>productFlavors</code> blocks in the
<code>build.gradle</code> file. These elements are still valid manifest entries and may
appear in manifests from older projects, imported projects, dependencies, and libraries. For
more information see,
<a href="{@docRoot}tools/studio/eclipse-migration-guide.html#manifest-settings">Manifest
Settings</a>.</p></li>
<li><strong>Dependencies</strong>
<p>Library dependencies are handled differently in Android Studio, using Gradle dependency
declarations and Maven dependencies for well-known local source and binary libraries with
Maven coordinates. For more information see,
<a href="{@docRoot}tools/studio/eclipse-migration-guide.html#dependencies">Dependencies</a></p>
</li>
<li><strong>Test code</strong>
<p>With Eclipse ADT, test code is written in separate projects and integrated through the
<code>&lt;instrumentation&gt;</code> element in your manifest file. Android Studio provides a
<code>AndroidTest</code> folder within your project so you can easily add and maintain your test
code within the same project view. JUnit tests can also be configured to run locally to reduce
testing cycles.</p></li>
<li><strong>Gradle-based build system</strong>
<p>In place of XML-based Ant build files, Android Studio supports Gradle build files, which
use the Gradle Domain Specific Language (DSL) for ease of extensibility and customization.
The Android Studio build system also supports
<a href="{@docRoot}tools/building/configuring-gradle.html#workBuildVariants"> build variants</a>,
which are combinations of <code>productFlavor</code> and <code>buildTypes</code>, to customize
your build outputs.</p></li>
<li><strong>User interface</strong>
<p>Android Studio provides an intuitive interface and menu options based on the
<a class="external-link" href="https://www.jetbrains.com/idea/" target="_blank">IntelliJ IDEA</a>
IDE. To become familiar with the IDE basics, such as navigation, code completion, and keyboard
shortcuts, see
<a class="external-link" href="https://www.jetbrains.com/idea/help/intellij-idea-quick-start-guide.html"
target="_blank">IntelliJ IDEA Quick Start Guide</a>.</p></li>
<li><strong>Developer tools versioning</strong>
<p>Android Studio updates independently of the Gradle-based build system so different build
settings can be applied across different versions of command line, Android Studio, and
continuous integration builds. For more information, see
<a href="{@docRoot}tools/building/configuring-gradle.html">Configuring Gradle Builds</a>.</p>
</li>
</ul>
<h2 id="prerequisites">Migration Prerequisites</h2>
<p>Before migrating your Eclipse ADT app to Android Studio, review the following steps to make
sure your project is ready for conversion, and verify you have the tool configuration you need in
Android Studio:</p>
<ul>
<li>In Eclipse ADT:
<ul>
<li>Make sure the Eclipse ADT root directory contains the <code>AndroidManifest.xml</code>
file. Also, the root directory must contain either the <code>.project</code> and
<code>.classpath</code> files from Eclipse or the <code>res/</code> and <code>src/</code>
directories.</li>
<li>Build your project to ensure your latest workspace and project updates are saved and
included in the import.</li>
<li>Comment out any references to Eclipse ADT workspace library files in the
<code>project.properties</code> or <code>.classpath</code> files for import. You can
add these references in the <code>build.gradle</code> file after the import. For more
information, see
<a href="{@docRoot}tools/building/configuring-gradle.html">Configuring Gradle Builds</a>.</li>
<li>It may be useful to record your workspace directory, path variables, and any actual path
maps that could be used to specify any unresolved relative paths, path variables, and
linked resource references. Android Studio allows you to manually specify any unresolved
paths during the import process.</li>
</ul>
</li>
<li>In Android Studio:
<ul>
<li>Make a note of any third-party Eclipse ADT plugins in use and check for equivalent features
in Android Studio or search for a compatible plugin in the
<a href="https://plugins.jetbrains.com/?androidstudio" class="external-link">IntelliJ Android
Studio Plugins</a> repository. Use the <strong>File &gt; Settings &gt; Plugins</strong> menu
option to manage plugins in Android Studio. Android Studio does not migrate any third-party
Eclipse ADT plugins.</li>
<li>If you plan to run Android Studio behind a firewall, be sure to set the proxy settings for
Android Studio and the SDK Manager. Android Studio requires an internet connection for
Setup Wizard synchronization, 3rd-party library access, access to remote repositories,
<a href="http://www.gradle.org" class="external-link">Gradle</a>
initialization and synchronization, and Android Studio version updates. For more information,
see <a href="{@docRoot}tools/studio/index.html#proxy">Proxy Settings</a>.</li>
<li>Use the <strong>File &gt; Settings &gt; System Settings</strong> menu option to verify the
current version and, if necessary, update Android Studio to the latest version from the
stable channel. To install Android Studio, please visit the
<a href="{@docRoot}sdk/index.html">Android Studio download page</a>.</li>
</ul>
</li>
</ul>
<h2 id="migrate">Importing Projects to Android Studio</h2>
<p>Android Studio provides a function for importing Eclipse ADT projects, which creates a new
Android Studio project and app modules based on your current
Eclipse ADT workspace and projects. No changes are made to your Eclipse project files. The Eclipse
ADT workspace becomes a new Android Studio project, and each Eclipse ADT project within the workspace
becomes a new Android Studio module. Each instance of Android Studio contains a project with one or
more app modules.</p>
<p>After selecting an Eclipse ADT project to import, Android Studio creates the Android
Studio project structure and app modules, generates the new Gradle-based build files and settings,
and configures the required dependencies. The import options also allow you to enter your workspace
directory and any actual path maps to handle any unresolved relative paths, path variables, and
linked resource references.</p>
<p>Depending on the structure of your Eclipse ADT development project, you should select specific
files for importing:</p>
<ul>
<li>For workspaces with multiple projects, select the project folder for each Eclipse ADT
project individually to import the projects into the same Android Studio project. Android
Studio combines the Eclipse ADT projects into a single Android Studio project with different app
modules for each imported project.</li>
<li>For Eclipse ADT projects with separate test projects, select the test project folder for
import. Android Studio imports the test project and then follows the dependency chain to import
the source project and any project dependencies.</li>
<li>If Eclipse ADT projects share dependencies within the same workspace, import each
project individually into Android Studio. Android Studio maintains the shared dependencies
across the newly created modules as part of the import process.</li>
</ul>
<p>To import a project to Android Studio:</p>
<ol>
<li>In Android Studio, from the main menu or the <strong>Welcome to Android Studio</strong> page,
choose <strong>File &gt; Import Project</strong>.</li>
<li> Select the Eclipse root project directory</strong> and click <strong>OK</strong>.
<p class="note"><strong>Note:</strong> The Eclipse root directory must contain the
<code>AndroidManifest.xml</code> file. Also, the root directory must contain either the
<code>.project</code> and <strong>.classpath</strong> files from Eclipse or the
<code>res/</code> and <code>src/</code> directories.</p>
</li>
<li>Follow the steps in the import wizard. </li>
<li>Start Android Studio and close any open Android Studio projects.</li>
<li>From the Android Studio menu select <strong>File &gt; New &gt; Import Project</strong>.
<p>Alternatively, from the <em>Welcome</em> screen, select <strong>Import project
(Eclipse ADT, Gradle, etc.)</strong>.</p></li>
<li>Select the Eclipse ADT project folder with the <code>AndroidManifest.xml</code> file
and click <strong>Ok</strong>.
<p> <img src="{@docRoot}images/tools/studio-select-project-forimport.png" alt="" /></p>
</li>
<li>Select the destination folder and click <strong>Next</strong>.
<p> <img src="{@docRoot}images/tools/studio-import-destination-dir.png" alt="" /></p></li>
<li>Select the import options and click <strong>Finish</strong>.
<p>The import process prompts to migrate any library and project dependencies to Android Studio,
and add the dependency declarations to the <code>build.gradle</code> file. The import process
also replaces any well-known source libraries, binary libraries, and JAR files that have known
Maven coordinates with Maven dependencies, so you no longer need to maintain these dependencies
manually. The import options also allow you to enter your workspace directory and any actual
path maps to handle any unresolved relative paths, path variables, and linked resource
references.</p>
<p> <img src="{@docRoot}images/tools/studio-import-options.png" alt="" /></p></li>
<li>Android Studio imports the app and displays the project import summary. Review the summary
for details about the project restructuring and the import process.
<p> <img src="{@docRoot}images/tools/studio-import-summary.png"/></p>
</li>
</ol>
<p>Android Studio imports the current dependencies, downloads libraries, and
creates an Android Studio project with the imported Eclipse project as the main module. Android
Studio also creates the required Gradle build files. </p>
<p>The import process replaces any JAR files and libraries with Gradle dependencies, and replaces
source libraries and binary libraries with Maven dependencies, so you no longer need to maintain
these files manually.</p>
<p class="note"><strong>Note:</strong> If there are references to Eclipse workspace library files,
comment them out in the <code>project.properties</code> or <code>.classpath</code> files
that you imported from the Eclipse project. You can then add these files in the
<code>build.gradle</code> file. See
<a href="{@docRoot}tools/building/configuring-gradle.html">Configuring Gradle Builds</a>. </p>
<p>After importing the project from Eclipse ADT to the new Android Studio project and module
structure, each app module folder in Android Studio contains the complete source set for that
module, including the {@code src/main} and {@code src/androidTest} directories, resources, build
file, and Android manifest. Before starting app development, you should resolve any issues shown in
the project import summary to make sure the project re-structuring and import process completed
properly.</p>
<p>For more help getting started with Android Studio and the IntelliJ user experience,
<a href="{@docRoot}tools/studio/index.html">learn more about Android Studio</a> and
read <a href="http://confluence.jetbrains.com/display/IntelliJIDEA/FAQ+on+Migrating+to+IntelliJ+IDEA"
class="external-link">FAQ on Migrating to IntelliJ IDEA</a>.</p>
<h3 id="post-migration">Validating imported projects</h3>
<p>After completing the import process, use the Android Studio <strong>Build</strong> and
<strong>Run</strong> menu options to build your project and verify the output. If your project
is not building properly, check the following settings:</p>
<ul>
<ul>
<li>Use the <strong>Android SDK</strong> button in Android Studio to launch the <a href=
"{@docRoot}tools/help/sdk-manager.html">SDK Manager</a> and verify the installed versions of SDK
tools, build tools, and platform match the settings for your Eclipse ADT project. Android Studio
inherits the SDK Manager and JDK settings from your imported Eclipse project.
</li>
<li>Use the <strong>File &gt; Project Structure</strong> menu option to verify additional
Android Studio settings:
<ul>
<li>Under <em>SDK Location</em> verify Android Studio has access to the correct SDK and
JDK locations and versions. </li>
<li>Under <em>Project</em> verify the Gradle version, Android Plugin version, and related
repositories.</li>
<li>Under <em>Modules</em> verify the app and module settings, such as signing configuration
and library dependencies. </li>
</ul>
</li>
<li>If your project depends on another project, make sure that dependency is defined properly in
the <code>build.gradle</code> file in the app module folder.</li>
</ul>
<p>If there still are unexpected issues when building and running your project in Android
Studio after you have checked these settings, consider modifying the Eclipse ADT project and
re-starting the import process. Importing an Eclipse ADT project to Android Studio creates a new
Android Studio project and does not impact the existing Eclipse ADT project. </p>
<p>To get started using Android Studio, review the
<a href="{@docRoot}tools/studio/index.html">Android Studio</a> features and
<a href="http://www.gradle.org">Gradle</a>-based build system to become familiar with the new
project and module structure, flexible build settings, and other advanced Android development
capabilities. For a comparison of Eclipse ADT and Android Studio features and usage, see
<a href="{@docRoot}tools/studio/eclipse-migration-guide.html">Transitioning to Android Studio from
Eclipse</a>. For specific Android Studio how-to documentation, see the pages in the
<a href="{@docRoot}tools/workflow/index.html">Workflow</a> section.
</p>

View File

@@ -0,0 +1,773 @@
page.title=Transition Guide for Eclipse ADT
@jd:body
<div id="qv-wrapper">
<div id="qv">
<h2>In this document</h2>
<ol>
<li><a href="#project-structure">Project Structure</a></li>
<li><a href="#manifest-settings">Manifest Settings</a></li>
<li><a href="#dependencies">Dependencies</a></li>
<li><a href="#build-process">Gradle-based Build Process</a></li>
<li><a href="#debug-inspect">Debugging and Code Inspections</a></li>
<li><a href="#resource-optimization">Resource Optimization</a></li>
<li><a href="#signing">App Signing</a></li>
<li><a href="#support-lib">Android Support Repository and Google Play services Repository</a></li>
<li><a href="#app-package">App Packaging</a></li>
<li><a href="#software-updates">Software Updates </a></li>
<li><a href="#version-control">Version Control</a></li>
</ol>
<h2>See also</h2>
<ol>
<li><a class="external-link"
href="http://confluence.jetbrains.com/display/IntelliJIDEA/FAQ+on+Migrating+to+IntelliJ+IDEA">
IntelliJ FAQ on migrating to IntelliJ IDEA</a></li>
<li><a class="external-link"
href="https://confluence.jetbrains.com/display/IntelliJIDEA/IntelliJ+IDEA+for+Eclipse+Users">
IntelliJ IntelliJ for Eclipse Users</a></li>
<li><a href="{@docRoot}tools/studio/index.html">Android Studio Overview</a> </li>
</ol>
</div>
</div>
<p>This document describes the differences between Eclipse ADT and Android Studio, including project
structure, build system, debugging, and application packaging. This guide is intended to help you
transition to using Android Studio as your development environment.</p>
<h2 id="project-structure">Project Structure </h2>
<p>Eclipse provides workspaces as a common area for grouping related projects, configurations, and
settings. In Android Studio, each instance of Android Studio contains a top-level project with one
or more app modules. Each app module folder contains the equivalent to an Eclipse
project, the complete source sets for that module, including {@code src/main} and
{@code src/androidTest} directories, resources, build file, and the Android manifest. In general,
to update and build your app you modify the files under each module's
{@code src/main} directory for source code updates, the <code>gradle.build</code> file for
build specification, and the files under {@code src/androidTest} directory for test case creation. </p>
<p>You can also customize the view of the project files in Android Studio to focus on specific
aspects of your app development: </p>
<ul>
<li><em>Packages</em> </li>
<li><em>Project Files</em> </li>
<li><em>Scratches</em> </li>
<li><em>Problems</em> </li>
<li><em>Production</em> </li>
<li><em>Tests</em> </li>
</ul>
<p>The following table shows the general mapping of the Eclipse ADT project structure and file
locations to Android Studio.</p>
<p class="table-caption" id="table-project-structure-mapping">
<strong>Table 1.</strong> Project structure mapping.</p>
<table>
<tr>
<th scope="col">Eclipse ADT</th>
<th scope="col">Android Studio</th>
</tr>
<tr>
<td>Workspace </td>
<td>Project </td>
</tr>
<tr>
<td>Project </td>
<td>Module </td>
</tr>
<tr>
<td>Project-specific JRE </td>
<td>Module JDK </td>
</tr>
<tr>
<td>Classpath variable </td>
<td>Path variable</td>
</tr>
<tr>
<td>Project dependency</td>
<td>Module dependency</td>
</tr>
<tr>
<td>Library Module</td>
<td>Library </td>
</tr>
<tr>
<td><code>AndroidManifest.xml</code></td>
<td><code>app/src/main/AndroidManifest.xml</code> </td>
</tr>
<tr>
<td><code>assets/</code></td>
<td><code>app/src/main/assets</code> </td>
</tr>
<tr>
<td><code>res/</code></td>
<td><code>app/src/main/res/</code> </td>
</tr>
<tr>
<td><code>src/</code></td>
<td><code>app/src/main/java/ </code> </td>
</tr>
<tr>
<td><code>tests/src/</code></td>
<td><code>app/src/androidTest/java/</code> </td>
</tr>
</table>
<p>Table 2 shows Eclipse ADT and Android Studio project views. </p>
<p class="table-caption" id="table2">
<strong>Table 2.</strong> Comparing project views.</p>
<table>
<tbody><tr>
<th>Eclipse ADT</th>
<th>Android Studio Project View</th>
<th>Android Studio Android View</th>
</tr>
<tr>
<td><img src="{@docRoot}images/tools/eclipse-notepad-pre-import--structure.png"/> </td>
<td><img src="{@docRoot}images/tools/studio-import-project-structure-project.png"/> </td>
<td><img src="{@docRoot}images/tools/studio-import-project-structure-android.png"/> </td>
</tr>
</tbody>
</table>
<p class="note"><strong>Note:</strong> Multiple instances of Android Studio can be used to develop
independent projects. </p>
<h2 id="manifest-settings">Manifest Settings</h2>
<p>Android Studio and <a href="http://www.gradle.org">Gradle</a>-based builds support
<a href="{@docRoot}tools/building/configuring-gradle.html#workBuildVariants"> build variants</a>,
which are combinations of <code>productFlavor</code> and <code>buildTypes</code>, to customize
your build outputs. To support these custom builds, several elements in the
<code>AndroidManifest.xml</code> file are now properties in the <code>defaultConfig</code> and
<code>productFlavors</code> blocks in the <code>build.gradle</code> file. The import process
copies these manifest settings to the properties in the <code>build.gradle</code> file.
These properties overwrite the settings in any other manifest files as shown in table 3. </p>
<p class="table-caption" id="table-manifest-gradle-settings">
<strong>Table 3.</strong> Manifest and Gradle property settings.</p>
<table>
<tr>
<th scope="col">Manifest Setting</th>
<th scope="col">build.gradle Setting</th>
</tr>
<tr>
<td><code>&lt;uses-sdk</code> <br>
<p><code>android:minSdkVersion</code></p>
<p><code>android:targetSdkVersion /&gt;</code></p>
</td>
<td> <br>
<p><code>minSdkVersion</code></p>
<p><code>targetSdkVersion</code></p> </td>
</tr>
<tr>
<td><code>&lt;manifest</code>
<p>package (Required in the default manifest file.) </p>
<p><code>android:versionCode</code></p>
<p><code>android:versionName /&gt;</code></p>
</td>
<td> <br>
<p><code>applicationId</code> (See
<a href="{@docRoot}tools/studio/index.html#app-id"> Application ID
for Package Identification</a>)</p>
<p><code>versionCode</code></p>
<p><code>versionName</code></p> </td>
</tr>
</table>
<p>Although these settings may no longer appear in the default app manifest file, they are still
valid manifest entries and may still appear in manifests from older projects, imported projects,
dependencies, and libraries.</p>
<p>The <code>package</code> element must still be specified in the manifest file. It is used in
your source code to refer to your <code>R</code> class and to resolve any relative activity/service
registrations. </p>
<p class="note"><strong>Note:</strong> When multiple manifests are present in your app, for
example a library manifest and a <code>src/main/</code> manifest, the build process combines
the manifest settings into a single merged manifest based on the manifest priority and
manifest merge settings. For more information about the manifest merge process and merge settings,
see
<a href="{@docRoot}tools/building/manifest-merger.html"> Manifest Merger</a>. </p>
<h2>Application ID for package identification </h2>
<p>With the Android build system, the <code>applicationId</code> attribute is used to
uniquely identify application packages for publishing. The application ID is set in the
<code>android</code> section of the <code>build.gradle</code> file. This field is populated in the
build file as part of the migration process. </p>
<pre>
apply plugin: &#39;com.android.application&#39;
android {
compileSdkVersion 19
buildToolsVersion "19.1"
defaultConfig {
<strong>applicationId "com.example.my.app"</strong>
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
...
</pre>
<p class="note"><strong>Note:</strong> The <code>applicationId</code> is specified only in your
<code>build.gradle</code> file, and not in the <code>AndroidManifest.xml</code> file.</p>
<p><a href="{@docRoot}tools/building/configuring-gradle.html#workBuildVariants">Build variants</a>
enable you to uniquely identify different
packages for each product flavor and build type. The application ID in the build type setting can
be added as a suffix to the ID specified for the product flavors. The following example adds the
<code>.debug</code> suffix to the application ID of the <code>pro</code> and <code>free</code>
product flavors: </p>
<pre>
productFlavors {
pro {
applicationId = &quot;com.example.my.pkg.pro&quot;
}
free {
applicationId = &quot;com.example.my.pkg.free&quot;
}
}
buildTypes {
debug {
applicationIdSuffix &quot;.debug&quot;
}
}
....
</pre>
<h2 id="dependencies">Dependencies</h2>
<p>During the import process, Android Studio imports the current Eclipse ADT dependencies and
downloads any project libraries as Android Studio modules. The dependency declarations are added to
the <code>build.gradle</code> file. The declarations include a
<a href="#scopes">dependency scope</a>, such as
<code>compile</code>, to specify in which builds the dependency is included. </p>
<p>The following example shows how to add an external library JAR dependency so it's included in
each compile:</p>
<pre>
dependencies {
compile files(&#39;libs/*.jar&#39;)
}
android {
...
}
</pre>
<p class="note"><strong>Note:</strong> Android Studio supports the Android ARchive (AAR) format
for the distribution of Android library projects as dependencies. For more information, see
<a href="{@docRoot}tools/building/configuring-gradle.html">Configuring Gradle Builds</a>. </p>
<p>The import process replaces any well-known source libraries, binary libraries, and JAR files
that have known Maven coordinates with Maven dependencies, so you no longer need to
maintain these dependencies manually. </p>
<p>Android Studio enables access to Maven, JCenter, and Ivy repositories with the
<code>repositories</code> block in the <code>build.gradle</code> as a shortcut to specifying
the URL of the repository.
<p>If there are required repositories not declared in the <code>build.gradle</code> file, first add
the repository to the <code>repositories</code> block, and then declare the dependencies in a way
that Maven, JCenter, or Ivy declare their artifacts. The following example shows how to add the
Maven repository with the guava 11.0.2 dependency using the <code>mavenCentral()</code> property: </p>
<pre>
repositories {
mavenCentral()
}
android {
...
}
dependencies {
compile &#39;com.google.guava:guava:11.0.2&#39;
instrumentationtestCompile &#39;com.squareup.fast-android:1:0.4&#39;
}
</pre>
<p>The Android Studio project created during the import process can also re-use any
dependencies on other components. These components can be external binary packages or other
<a href="http://www.gradle.org">Gradle</a> projects. If a dependency has dependencies of its own,
those dependencies are also included in the new Android Studio project. </p>
<p class="note"><strong>Note:</strong> If there were references to Eclipse ADT workspace library
files in the <code>project.properties</code> or <code>.classpath</code> files
that were not imported from the Eclipse project, you can now add dependencies to these library files
in the <code>build.gradle</code> file. For more information, see
<a href="{@docRoot}tools/building/configuring-gradle.html">Configuring Gradle Builds</a>. </p>
<h3 id="scopes">Dependency and compilation scopes </h3>
<p>Android Studio supports compilation scopes to customize which dependencies get
included in each build, for example assigning different dependencies to different
<a href="{@docRoot}tools/building/configuring-gradle.html#workBuildVariants"> build variants</a>.</p>
<p>This list shows the Android Studio scope names and definitions: </p>
<ul>
<li>compile - <code>compile</code> </li>
<li>run time - <code>package</code></li>
<li>testCompile - <code>AndroidTestCompile</code></li>
<li>testRuntime - <code>AndroidTestRunPackage</code></li>
<li>buildTypeCompile - <code>buildTypeCompile</code> </li>
<li>productFlavorCompile - <code>productFlavorCompile</code> </li>
</ul>
<p class="note"><strong>Note:</strong> Dependencies for library projects must be added with the
<code>compile</code> scope. </p>
<p>With the <a href="http://www.gradle.org">Gradle</a>-based DSL, you can also add custom
dependency scopes, such as <code>betaCompile file('libs/protobug.jar')</code> to define a beta
build dependency. </p>
<p>The scope and compilation configuration in the build file determine the
components compiled into the app, added to the compilation classpath, and packaged in the final
APK file. Based on the dependency and compilation scope, different compilation configurations
can be specified to include the dependencies and classpaths, for example: </p>
<ul>
<li><code>compile</code> - for the main application. </li>
<li><code>androidTestCompile</code> - for the test application. </li>
<li><code>debugCompile</code> - for the debug buildType application.</li>
<li><code>releaseCompile</code> - for the release buildType application. </li>
</ul>
<p class="note"><strong>Note:</strong> Because its not possible to build an APK that does not
have an associated <code>buildType</code>, the APK built from your app is always configured with
at least two dependency and compile configurations: <code>compile</code> and
<code>debugCompile</code>. </p>
<p>Unlike Eclipse ADT, by default Android Studio does not compile your code when there are changes.
Use the <strong>File &gt; Settings &gt; Build, Execution, Deployment Compiler</strong> option
to enable automatic compilation. </p>
<h2 id="build-process">Gradle-based Build Process </h2>
<p>Android Studio imports the Eclipse ADT Ant-based
build tasks and converts the tasks to <a href="http://www.gradle.org">Gradle</a>-based build tasks.
These new build tasks include the
main <code>assemble</code> task and at least two outputs based on the default build types:
a <code>debug</code> APK and a
<code>release</code> APK. Each of these build tasks has its own Android build system anchor task
to facilitate building them independently: </p>
<ul>
<li><code>assemble</code></li>
<li><code>assembleDebug</code></li>
<li><code>assembleRelease</code></li>
</ul>
<p>In Android Studio, you can view all the supported build tasks in the
<em>Gradle</em> project tab. </p>
<p>With the <a href="http://www.gradle.org">Gradle</a>-based build system, Android Studio uses a
<a href="http://www.gradle.org">Gradle</a> wrapper to fully integrate the
Android Plugin for Gradle. The Android Plugin for Gradle also
runs independent of Android Studio. This means that with Android Studio build system your build
output is always the same, whether you build your Android apps from Android Studio, from the
command line on your machine, or on machines where Android Studio is not installed (such as
continuous integration servers). </p>
<p>Unlike Eclipse ADT with dependent plugin and build updates, the <code>build.gradle</code>
files allow you to customize the build settings for each Android Studio module and build variant,
so the build versions can be set independently, and are not dependent on the Android Studio
or build tools versions. This makes it easy to maintain and build legacy apps along with your
current app, using build variants to generate different APKs from the same app modules, but
built with different build versions and build chains. </p>
<p>For more details about the Android Studio build system, see
<a href="{@docRoot}sdk/installing/studio-build.html">Build System Overview</a>.</p>
<h3>Using the Android Studio build system's declarative logic </h3>
<p>In contrast with the XML statements in Ant build files, the Android build system and
<a href="http://www.gradle.org">Gradle</a> DSL provide a declarative build language so you can
easily extend the Gradle-based build process beyond the typical XML build tasks. For example,
this build file shows how to define a custom function to inject a dynamic <code>versionCode</code>
in build outputs: </p>
<pre>
def getVersionCode) {
def code = …
return code
}
android {
defaultConfig {
versionCode getVersionCode()
}
}
</pre>
<p>This example shows how to append <em>debug</em> to your package and version names used in the
<code>debug</code> build variant of your app: </p>
<pre>
android {
buildTypes {
debug {
packageNameSuffix .debug
versionNameSuffix -DEBUG
}
beta {
}
}
}
</pre>
<p>You can also use the declarative DSL in the Android build system to generate custom build
versions, for example a debuggable version of your release APK. This examples adds the
<code>debuggable true</code> property to the <code>release</code> build type in the
<code>build.gradle</code> file to build an identical debuggable version of the release package. </p>
<pre>
android {
buildTypes {
debugRelease.initWith(buildTypes.release)
debugRelease {
debuggable true
packageNameSuffix &#39;.debugrelease&#39;
signingConfig signingConfigs.debug
}
}
sourceSets.debugRelease.setRoot(&#39;src/release&#39;)
}
</pre>
<h2 id="debug-inspect">Debugging and Code Inspections</h2>
<p>Using code inspection tools such as <a href="{@docRoot}tools/help/lint.html">lint</a> is a
standard part of Android development. Android Studio extends
<a href="{@docRoot}tools/help/lint.html">lint</a> support with additional
<a href="{@docRoot}tools/help/lint.html">lint</a> checks and supports Android
<a href="{@docRoot}tools/debugging/annotations.html">annotations</a> that
allow you to help detect more subtle code problems, such as null pointer exceptions and resource
type conflicts. Annotations are added as metadata tags that you attach to variables, parameters,
and return values to inspect method return values, passed parameters, and local variables and
fields. </p>
<p>For more information on enabling <a href="{@docRoot}tools/help/lint.html">lint</a> inspections
and running <a href="{@docRoot}tools/help/lint.html">lint</a>,
see <a href="{@docRoot}tools/debugging/improving-w-lint.html">Improving Your Code with lint</a>.
For more information about using annotations, see
<a href="{@docRoot}tools/debugging/annotations.html#annotations">Improving your Code with
Annotations</a>. </p>
<p>In addition to code inspection, Android Studio provides an integrated
<a href="{@docRoot}tools/studio/index.html#mem-cpu">memory and CPU monitor</a> view so you
can more easily monitor your app's performance and memory usage to track CPU usage, find
deallocated objects, locate memory leaks, and track the amount of memory the connected device is
using. </p>
<h2 id="resource-optimization">Resource Optimization </h2>
<p>After importing and building your app, Android Studio supports several
<a href="http://www.gradle.org">Gradle</a>-based properties to help you minimize your app's
resource utilization. </p>
<h3>Resource shrinking</h3>
<p>In Android Studio, resource shrinking enables the automatic removal of unused resources from
your packaged app and also removes resources from library dependencies if the resources are not
actually used by your app.</p>
<p>Use the <code>shrinkResources</code> attribute in the <code>buildType</code> block in your
<code>build.gradle</code> file to enable resource shrinking. For example, if your application is
using <a href="{@docRoot}google/play-services/index.html">Google Play services</a>
to access Google Drive functionality, and you are not currently using
<a href="{@docRoot}google/play-services/plus.html">Google+ Sign In</a>, then
this setting removes the various drawable assets for the <code>SignInButton</code> buttons. </p>
<p class="note"><strong>Note:</strong> Resource shrinking works in conjunction with code shrinking
tools, such as <a href="{@docRoot}tools/help/proguard.html">ProGuard</a>. </p>
<p>To enable resource shrinking, update the <code>buildTypes</code> block in the
<code>build.gradle</code> file to include <code>minifyEnabled true</code>,
<code>shrinkResources true</code>, and <code>proguardFiles</code> settings as shown in the
following example <a href="http://www.gradle.org">Gradle</a> build file.</p>
<pre>
android {
...
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
</pre>
<h3>Filtering language resources</h3>
<p>Use the <code>resConfig</code> attribute in your <code>build.gradle</code> file
to filter the locale resources included in your packaged app. This filtering can be especially
useful when library dependencies such as <code>appcompat-v7</code> and other libraries such as
<code>google-play-services_lib</code> are included in your app. </p>
<p>The following example limits the locale resources to three language settings: <code>en</code>,
<code>de</code>, and <code>es</code>:</p>
<pre>
apply plugin: 'android'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
versionCode 1
versionName "1.0"
resConfigs "en", "de", "es" //Define the included language resources.
}
...
</pre>
<h4>Filtering bundled resources</h4>
<p>You can also use the <code>resConfig</code> build setting to limit the bundled resources
in any resource folder. For example, you could also add <code>resConfigs</code>
settings for density folders, such as <code>mdpi</code> or <code>hdpi</code> to limit the drawable
resources that are packaged in your <code>APK</code> file. This example limits the app's
bundled resources to medium-density (MDPI) and high-density (HDPI) resources. </p>
<pre>
android {
defaultConfig {
...
resConfigs "mdpi", "hdpi"
}
}
</pre>
For more information about screen and resource densities, see
<a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple Screens</a>
and <a href="{@docRoot}training/multiscreen/screendensities.html">Supporting Different Densities</a>.
<h3>Resource merging </h3>
<p>With Android Studio, identical resources, such as copies of launcher and menu icons, may end up
in different resource folders throughout your app. To reduce resource duplication and improve
the performance of your app, Android Studio merges resources with an identical resource name, type,
and qualifier into a single resource and passes the single, merged resource to the Android Asset
Packaging Tool (AAPT) for distribution in the APK file. </p>
<p>The resource merging process looks for identical resources in the following <code>/res/</code>
folders: </p>
<ul>
<li>AAR bundles of library project dependencies</li>
<li><code>src/main/</code> </li>
<li><code>src/<em>productFlavor</em>/</code> </li>
<li><code>src/<em>buildType</em>/</code> </li>
</ul>
<p>Identical resources are merged in the following low to high priority order: </p>
<pre>
dependencies --> src/main/ --> src/productFlavor/ --> src/buildType/
</pre>
<p>For example, if the <code>res/ic_menu.png</code> file is included in both the
<code>src/main/res/</code> and <code>src/productFlavor/res/</code> folders, the resources are merged
so only the file with the higher priority, in this case the <code>src/productFlavor/res/</code>
file, is included in the APK file. </p>
<p class="note"><strong>Note:</strong> Identical resources in the same source set are not merged
and instead generate a resource merge error. This can happen if the <code>sourceSet</code> property
in the <code>build.gradle</code> file is used to define multiple source sets, for example
<code>src/main/res/</code> and <code>src/main/res2/</code>, and these folders contain identical
resources. </p>
<h2 id="signing">App Signing and ProGuard </h2>
<p>Based on the imported Eclipse ADT app settings, Android Studio automatically sets up your app
signing and maintains any ProGuard settings. </p>
<h3>App Signing</h3>
<p>If your app used a debug certificate in Eclipse ADT, Android Studio continues to reference that
certificate. Otherwise, the <code>debug</code> configuration uses the Android Studio generated
debug keystore, with a known password and a default key with a known password located in
<code>$HOME/.android/debug.keystore</code>. The <code>debug</code> build type is set to use this
debug <code>SigningConfig</code> automatically when you run or debug your project
from Android Studio. </p>
<p>In release mode, Android Studio applies the release certificate used in Eclipse ADT. If no
release certificate was located during the import process, add the release signing configuration to
the <code>build.gradle</code> file or use the <strong> Build > Generate Signed APK</strong> menu
option to open the Generate Signed APK Wizard. For more information about signing your app, see
<a href="{@docRoot}tools/publishing/app-signing.html">Signing Your Applications</a>. </p>
<h3>ProGuard</h3>
<p>If the <a href="{@docRoot}tools/help/proguard.html">ProGuard</a> option is specified in the
<code>project.properties</code> file in the Eclipse ADT project, Android Studio imports the
<a href="{@docRoot}tools/help/proguard.html">ProGuard</a> files and adds the
<a href="{@docRoot}tools/help/proguard.html">ProGuard</a> settings to the
<code>build.gradle</code> file. <a href="{@docRoot}tools/help/proguard.html">ProGuard</a> is
supported through the <code>minifyEnabled</code> property as shown in this example. </p>
<pre>
android {
buildTypes {
release {
minifyEnabled true
proguardFile getDefaultProguardFile(&#39;proguard-android.txt&#39;)
}
}
productFlavors {
flavor1 {
}
flavor2 {
proguardFile &#39;some-other-rules.txt&#39;
}
}
}
</pre></p>
<h2 id="support-lib">Android Support Repository and Google Play services Repository</h2>
<p>While Eclipse ADT uses the Android <a href="{@docRoot}tools/support-library/index.html">Support
Library</a> and Google Play services Library, Android Studio replaces these libraries during the
import process with the Android Support Repository and Google Repository to maintain
compatible functionality and support new Android features. Android Studio adds these dependencies
as Maven dependencies using the known Maven coordinates, so these dependencies do not require
manual updates. </p>
<p>In Eclipse, in order to use a
<a href="{@docRoot}tools/support-library/index.html">Support Library</a>, you must modify your
project's classpath dependencies within your development environment for each
<a href="{@docRoot}tools/support-library/index.html">Support Library</a> you want to use. In
Android Studio, you no longer need to copy library sources into your
own projects, you can simply declare a dependency and the library is automatically downloaded and
merged into your project. This includes automatically merging in resources, manifest entries,
<a href="{@docRoot}tools/help/proguard.html">ProGuard</a> exclusion rules, and custom lint rules
at build time. </p>
<p>Android Studio also supports binary library Android ARchives (AARs). AARs are a library project's
main output as a combination of compiled code (as a jar file and/or native .so files) and
resources (manifest, res, assets). <p/>
<h2 id="app-package">App Packaging</h2>
<p>The Android build system introduces the use of the <code>applicationId</code> attribute to
uniquely identify application packages for publishing. The application ID is set in the
<code>android</code> section of the <code>build.gradle</code> file. </p>
<p>The <code>applicationId</code> is specified only in your <code>build.gradle</code> file, and
not in the
<code>AndroidManifest.xml</code> file. The Gradle-based build system enables you
to uniquely identify different packages for each build variant based on product flavors and build
types. You can also add the <code>applicationIdSuffix</code> property to the build type in the
<code>build.gradle</code> file to append an identifier, such as '.debug', to the application ID
generated for each product flavor. </p>
<h2 id="software-updates">Software Updates</h2>
<p>Android Studio provides several levels of update and maintenance to help you keep Android Studio
up-to-date based on your code-level preference: </p>
<ul>
<li><strong>Canary channel</strong>: Canary builds provide bleeding edge releases and are updated
about weekly. These builds do get tested, but are still subject to bugs, as these are
early releases. This is not recommended for production.</li>
<li><strong>Dev channel</strong>: Dev builds are canary builds that passed initial testing and
usage. They are updated roughly bi-weekly or monthly.</li>
<li><strong>Beta channel</strong>: Beta builds provide beta-quality releases for final testing
and feedback before a production release.</li>
<li><strong>Stable channel</strong>: Stable builds provide stable, production-ready release
versions.</li>
</ul>
<h2 id="version-control">Version Control </h2>
<p>Eclipse ADT supports version control through the use of plugins, such as the EGit and Subversive
plug-ins. </p>
<p>Android Studio supports a variety of version control systems (Git, GitHub, CVS, Mercurial,
Subversion, and Google Cloud) so version control operations can continue from within Android
Studio. </p>
<p>After importing your Eclipse ADT app into Android Studio, use the
Android Studio <em>VCS</em> menu options to enable VCS support for the desired version control
system, create a repository, import the new files into version control, and perform other version
control operations. </p>
<p class="note"><strong>Note:</strong> You can also use the
<strong>File &gt; Setting &gt; Version Control</strong> menu option to setup and modify the version
control settings. </p>
<h3>Files to ignore </h3>
<p>A number of Android Studio files are typically not added to version control as these are
temporary files or files that get overwritten with each build. These files are listed in
an exclusion file, such as <code>.gitignore</code>, for the project and each app module.
Typically, the following files are excluded from version control: </p>
<ul>
<li>.gradle </li>
<li>/local.properties </li>
<li>/.idea/workspace.xml </li>
<li>/.idea/libraries </li>
<li>.DS_Store</li>
<li>/build </li>
<li>/captures </li>
</ul>

View File

@@ -176,7 +176,7 @@ To configure custom build settings in an Android Studio project, see
<a href="{@docRoot}tools/building/configuring-gradle.html">Configuring Gradle Builds</a>.</p>
<h3>Application ID for package identification </h3>
<h3 id="app-id">Application ID for package identification </h3>
<p>With the Android build system, the <em>applicationId</em> attribute is used to
uniquely identify application packages for publishing. The application ID is set in the
<em>android</em> section of the <code>build.gradle</code> file.

View File

@@ -151,12 +151,7 @@
<div class="nav-section-header"><a href="<?cs var:toroot ?>tools/help/index.html"><span
class="en">Tools Help</span></a></div>
<ul>
<li class="nav-section">
<div class="nav-section-header"><a href="<?cs var:toroot ?>tools/help/adb.html">adb</a></div>
<ul>
<li><a href="<?cs var:toroot ?>tools/help/shell.html">Shell commands</a></li>
</ul>
</li>
<li><a href="<?cs var:toroot ?>tools/help/adb.html">adb</a></li>
<li><a href="<?cs var:toroot ?>tools/help/android.html">android</a></li>
<li><a href="<?cs var:toroot ?>tools/help/avd-manager.html">AVD Manager</a></li>
<li><a href="<?cs var:toroot ?>tools/help/bmgr.html">bmgr</a>
@@ -173,7 +168,6 @@ class="en">Tools Help</span></a></div>
<li><a href="<?cs var:toroot ?>tools/help/mksdcard.html">mksdcard</a></li>
<li><a href="<?cs var:toroot ?>tools/help/proguard.html" zh-cn-lang="ProGuard">ProGuard</a></li>
<li><a href="<?cs var:toroot ?>tools/help/sdk-manager.html">SDK Manager</a></li>
<li><a href="<?cs var:toroot ?>tools/help/sqlite3.html">sqlite3</a></li>
<li><a href="<?cs var:toroot ?>tools/help/systrace.html">Systrace</a></li>
<li><a href="<?cs var:toroot ?>tools/help/gltracer.html">Tracer for OpenGL ES</a></li>
<li><a href="<?cs var:toroot ?>tools/help/traceview.html">Traceview</a></li>
@@ -200,66 +194,6 @@ class="en">Tools Help</span></a></div>
</ul>
</li><!-- end of build system -->
<!-- Performance Tools menu-->
<li class="nav-section">
<div class="nav-section-header">
<a href="<?cs var:toroot ?>tools/performance/index.html">Peformance Tools</a>
</div>
<ul>
<li><a href="<?cs var:toroot ?>tools/performance/debug-gpu-overdraw/index.html">
Overdraw Debugger</a>
</li>
<li><a href="<?cs var:toroot ?>tools/performance/profile-gpu-rendering/index.html">
Rendering Profiler</a>
</li>
<li class="nav-section">
<div class="nav-section-header">
<a href="<?cs var:toroot ?>tools/performance/hierarchy-viewer/index.html">
Hierarchy Viewer</a></div>
<ul>
<li><a href="<?cs var:toroot ?>tools/performance/hierarchy-viewer/setup.html"><span
class="en">Setup</span></a>
</li>
<li><a href="<?cs var:toroot ?>tools/performance/hierarchy-viewer/profiling.html"><span
class="en">Profiling</span></a>
</li>
</ul>
</li>
<li class="nav-section">
<div class="nav-section-header">
<a href="<?cs var:toroot ?>tools/performance/comparison.html">
Memory Profilers</a></div>
<ul>
<li><a href="<?cs var:toroot ?>tools/performance/memory-monitor/index.html"><span
class="en">Memory Monitor</span></a>
</li>
<li><a href="<?cs var:toroot ?>tools/performance/heap-viewer/index.html"><span
class="en">Heap Viewer</span></a>
</li>
<li><a href="<?cs var:toroot ?>tools/performance/allocation-tracker/index.html"><span
class="en">Allocation Tracker</span></a>
</li>
</ul>
</li>
<li><a href="<?cs var:toroot ?>tools/performance/traceview/index.html">
Traceview</a>
</li>
<li><a href="<?cs var:toroot ?>tools/performance/systrace/index.html">
Systrace</a>
</li>
<li class="nav-section">
<div class="nav-section-header">
<a href="<?cs var:toroot ?>tools/performance/batterystats-battery-historian/index.html">
Battery Profilers</a></div>
<ul>
<li><a href="<?cs var:toroot ?>tools/performance/batterystats-battery-historian/charts.html"><span
class="en">Historian Charts</span></a>
</li>
</ul>
</li>
</ul>
</li><!-- End Performance Tools menu-->
<!-- Testing Tools menu-->
<li class="nav-section">
@@ -357,7 +291,15 @@ class="en">Data Binding Library</span></a></div>
<span class="en">Eclipse with ADT</span></a>
</div>
<ul>
<li><a href="<?cs var:toroot ?>sdk/installing/migrate.html">Migrating to Android Studio</a></li>
<li class="nav-section">
<div class="nav-section-header"><a href="<?cs var:toroot ?>sdk/installing/migrate.html">
<span class="en">Migrating to Android Studio</span></a></div>
<ul>
<li><a href="<?cs var:toroot ?>tools/studio/eclipse-transition-guide.html">
Transition Guide</span></a> </li>
</ul>
</li>
<li><a href="<?cs var:toroot ?>sdk/installing/installing-adt.html">
<span class="en">Installing the Eclipse Plugin</span></a></li>
<li><a href="<?cs var:toroot ?>tools/projects/projects-eclipse.html">Managing Projects</a></li>