1page.title=Android Studio Overview
2page.image=images/cards/card-android-studio-overview_16x9_2x.jpg
3page.metaDescription=Learn about the official IDE for Android.
4page.tags=studio,sdk,tools,firstapp
5@jd:body
6
7<div id="qv-wrapper">
8<div id="qv">
9
10    <h2>In this document</h2>
11    <ol>
12      <li><a href="#project-structure">Project and File Structure</a></li>
13      <li><a href="#build-system">Android Build System</a></li>
14      <li><a href="#debug-perf">Debug and Performance</a></li>
15
16
17    </ol>
18
19  <h2>See also</h2>
20  <ol>
21    <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>
22  </ol>
23
24</div>
25</div>
26
27
28<p>Android Studio is the official IDE for Android application development,
29based on <a class="external-link" href="https://www.jetbrains.com/idea/" target="_blank">IntelliJ IDEA</a>.
30On top of the capabilities you expect from IntelliJ,
31Android Studio offers:</p>
32
33<ul>
34  <li>Flexible Gradle-based build system</li>
35  <li>Build variants and multiple <code>apk</code> file generation</li>
36  <li>Code templates to help you build common app features</li>
37  <li>Rich layout editor with support for drag and drop theme editing</li>
38  <li>{@code lint} tools to catch performance, usability, version compatibility, and other problems</li>
39  <li>ProGuard and app-signing capabilities</li>
40  <li>Built-in support for
41  <a href="http://developers.google.com/cloud/devtools/android_studio_templates/">Google Cloud Platform</a>,
42  making it easy to integrate Google Cloud Messaging and App Engine</li>
43  <li>And much more</li>
44</ul>
45
46
47<p>If you're new to Android Studio or the IntelliJ IDEA interface, this
48page provides an introduction to some key Android
49Studio features.</p>
50
51<p>For specific Android Studio how-to documentation, see the pages in the <a href=
52"{@docRoot}tools/workflow/index.html">Workflow</a> section, such as <a href=
53"{@docRoot}sdk/installing/create-project.html">Managing Projects from Android Studio</a> and
54<a href="{@docRoot}tools/building/building-studio.html">Building and Running from Android
55Studio</a>. For a summary of the latest changes to Android Studio, see the
56<a href="{@docRoot}tools/revisions/studio.html">Android Studio Release Notes</a>.</p>
57
58
59
60
61<h2 id="project-structure">Project and File Structure</h2>
62
63<h3 id="project-view"><em>Android</em> project view</h3>
64<p>By default, Android Studio displays your project files in the <em>Android</em> project view. This
65view shows a flattened version of your project's structure that provides quick access to the key
66source files of Android projects and helps you work with the
67<a href="{@docRoot}sdk/installing/studio-build.html">Gradle-based build system</a>.
68The <em>Android</em> project view:</p>
69
70<ul>
71  <li>Shows the most important source directories at the top level of the module hierarchy.</li>
72  <li>Groups the build files for all modules in a common folder.</li>
73  <li>Groups all the manifest files for each module in a common folder.</li>
74  <li>Shows resource files from all Gradle source sets.</li>
75  <li>Groups resource files for different locales, orientations, and screen types in a single
76  group per resource type.</li>
77</ul>
78
79     <img src="{@docRoot}images/tools/projectview01.png" />
80     <p class="img-caption"><strong>Figure 1.</strong> Show the Android project view.</p>
81     <img src="{@docRoot}images/tools/studio-projectview_scripts.png"  />
82     <p class="img-caption"><strong>Figure 2.</strong> Show project build files.</p>
83
84<p>The <em>Android</em> project view shows all the build files at the top level of the project
85hierarchy under <strong>Gradle Scripts</strong>. Each project module appears as a folder at the
86top level of the project hierarchy and contains these four elements at the top level:</p>
87
88<ul>
89  <li><code>java/</code> - Source files for the module.</li>
90  <li><code>manifests/</code> - Manifest files for the module.</li>
91  <li><code>res/</code> - Resource files for the module.</li>
92  <li><code>Gradle Scripts/</code> - Gradle build and property files.</li>
93</ul>
94
95<p>For example, <em>Android</em> project view groups all the instances of the
96<code>ic_launcher.png</code> resource for different screen densities under the same element.</p>
97
98<p class="note"><strong>Note:</strong> The project structure on disk differs from this flattened
99representation. To switch to back to the segregated project view, select <strong>Project</strong>
100from the <strong>Project</strong> drop-down. </p>
101
102
103
104<h3 id="other-views">Other Android Studio views</h3>
105<p>When you use the <em>Project</em> view in Android Studio, you
106should notice that the project structure appears different than you may be used to in Eclipse. Each
107instance of Android Studio contains a project with one or more application modules. Each
108application module folder contains the complete source sets for that module, including
109{@code src/main/} and {@code src/androidTest/} directories, resources, build
110file and the Android manifest. For the most part, you will need to modify the files under each
111module's {@code src/main/} directory for source code updates, the gradle.build file for build
112specification and the files under {@code src/androidTest/} directory for test case creation.
113
114    <p>  <img src="{@docRoot}images/tools/studio-project-layout.png" alt="" /></p>
115    <p>  <class="img-caption"><strong>Figure 3.</strong> View Android Studio <em>Project</em>
116         structure.</p>
117
118<p>You can also customize the view of the project files to focus on specific aspects of your app
119development: </p>
120
121<ul>
122  <li><em>Packages</em> </li>
123  <li><em>Project Files</em> </li>
124  <li><em>Scratches</em> </li>
125  <li><em>Problems</em> </li>
126  <li><em>Production</em> </li>
127  <li><em>Tests</em> </li>
128</ul>
129
130<p>For example, selecting the <strong>Problems</strong> view of your project displays links to the
131source files containing any recognized coding and syntax errors, such as missing an XML element
132closing tag in a layout file.<p>
133
134<p>For more information, see
135<a class="external-link" href="http://confluence.jetbrains.com/display/IntelliJIDEA/Project+Organization">IntelliJ project organization</a>
136and <a href="{@docRoot}tools/projects/index.html">Managing Projects</a>.</p>
137
138
139
140<h2 id="build-system">Android Build System</h2>
141<p>The Android build system is the toolkit you use to build, test, run and package
142your apps. This build system replaces the Ant system used with Eclipse ADT. It can run as an
143integrated tool from the Android Studio menu and independently from the command line. You can use
144the features of the build system to:</p>
145
146<ul>
147    <li>Customize, configure, and extend the build process.</li>
148    <li>Create multiple APKs for your app with different features using the same project and
149    modules.</li>
150    <li>Reuse code and resources across source sets.</li>
151</ul>
152
153<p>The flexibility of the Android build system enables you to achieve all of this without
154modifying your app's core source files. To build an Android Studio project, see
155<a href="{@docRoot}tools/building/building-studio.html">Building and Running from Android Studio</a>.
156To configure custom build settings in an Android Studio project, see
157<a href="{@docRoot}tools/building/configuring-gradle.html">Configuring Gradle Builds</a>.</p>
158
159
160
161<h2 id="debug-perf">Debug and Performance</h2>
162<p>Android Studio provides a number of improvements to assist you in debugging and improving the
163performance of your code, including an improved virtual device management, inline debugging, and
164performance analysis tools.</p>
165
166<h3>Android Virtual Device (AVD) Manager</h3>
167<p>AVD Manager has updated screens with links to help you select the most popular device
168configurations, screen sizes and resolutions for your app previews.</p>
169Click the <strong>Android Virtual Device Manager</strong>
170<img src="{@docRoot}images/tools/avd-manager-studio.png"
171style="vertical-align:bottom;margin:0;height:19px" /> in the toolbar to open it and create
172new virtual devices for running your app in the emulator.</p>
173
174<p>The AVD Manager comes with emulators for Nexus 6 and Nexus 9 devices and also supports
175creating custom Android device skins based on specific emulator properties and assigning those
176skins to hardware profiles. Android Studio installs the Intel&#174; x86 Hardware Accelerated Execution
177Manager (HAXM) emulator accelerator and creates a default emulator for quick app prototyping.</p>
178
179<p>For more information, see <a href="{@docRoot}tools/devices/managing-avds.html">Managing AVDs</a>.</p>
180
181
182<h3 id="inline-debug">Inline debugging</h3>
183<p>Use inline debugging to enhance your code walk-throughs in the debugger view
184with inline verification of references, expressions, and variable values. Inline debug information
185includes: </p>
186<ul>
187 <li>Inline variable values</li>
188 <li>Referring objects that reference a selected object </li>
189 <li>Method return values</li>
190 <li>Lambda and operator expressions</li>
191 <li>Tool tip values</li>
192</ul>
193
194<p>To enable inline debugging, in the <em>Debug</em> window click the Settings icon
195<img src="{@docRoot}images/tools/studio-debug-settings-icon.png"/> and select the
196check box for <strong>Show Values In Editor</strong>.</p>
197
198<h3 id="mem-cpu">Memory and CPU monitor</h3>
199<p>Android Studio provides a memory and CPU monitor view so you can more easily monitor your
200app's performance and memory usage to track CPU usage, find deallocated objects, locate memory
201leaks, and track the amount of memory the connected device is using. With your app running on a
202device or emulator, click the <strong>Android</strong> tab in the lower left corner of the
203runtime window to launch the Android runtime window. Click the <strong>Memory</strong> or
204<strong>CPU</strong> tab. </p>
205
206<img src="{@docRoot}images/tools/studio-memory-monitor.png" srcset="{@docRoot}images/tools/studio-memory-monitor_2x.png 2x" width"635" height="171" alt="" />
207    <p class="img-caption"><strong>Figure 4.</strong> Monitor memory and CPU usage.</p>
208
209<h4 id="heap-dump">Heap dump </h4>
210<p>When you're monitoring memory usage in Android Studio you can, at the same time, initiate
211garbage collection and dump the Java heap to a heap snapshot in an Android-specific HPROF binary
212format file. The HPROF viewer displays classes, instances of each class, and a reference tree to
213help you track memory usage and find memory leaks. </p>
214
215<img src="{@docRoot}images/tools/studio-hprof-viewer.png" alt="" />
216    <p class="img-caption"><strong>Figure 5.</strong> HPROF viewer with heap dump.</p>
217
218<p>To create a snapshot of the Android app heap memory, click the
219Dump Java Heap icon (<img src="{@docRoot}images/tools/studio-dump-heap-icon.png" style="vertical-align:bottom;margin:0;height:17px"/>)
220in the Memory Monitor. Android Studio creates the heap snapshot file with the filename
221<code>Snapshot-yyyy.mm.dd-hh.mm.ss.hprof</code>
222in the <em>Captures</em> tab. Double-click the heap snapshot file to open the HPROF viewer.</p>
223
224<p>To convert a heap dump to standard HPROF format in Android Studio, right-click a heap
225snapshot in the <em>Captures</em> view and select <strong>Export to standard .hprof</strong>. </p>
226
227
228
229<h4 id="alloc-tracker">Allocation tracker </h4>
230<p>Android Studio allows you to track memory allocation as it monitors memory use. Tracking memory
231allocation allows you to monitor where objects are being allocated when you perform certain actions.
232Knowing these allocations enables you to  adjust the method
233calls related to those actions to optimize your app's performance and memory use. </p>
234
235<img src="{@docRoot}images/tools/studio-allocation-tracker.png" alt="" />
236    <p class="img-caption"><strong>Figure 6.</strong> Allocation tracker.</p>
237
238<p>Perform the following steps to track and analyze allocations: </p>
239<ol>
240  <li>Click the Start/Stop Allocation Tracking icon
241    (<img src="{@docRoot}images/tools/studio-allocation-tracker-icon.png" style="vertical-align:bottom;margin:0;height:17px"/>) in the
242    <a href="#mem-cpu">Memory Monitor</a>. Android Studio starts tracking memory allocations.</li>
243  <li>Perform the tasks whose mallocs you want to track. </li>
244  <li>Click the Start/Stop Allocation Tracking icon again. Android Studio stops tracking mallocs
245    and saves the data to a file named <code>Allocation-yyyy.mm.dd-hh.mm.ss.alloc</code>. The
246    resulting file appears in the <em>Captures</em> tab. </li>
247  <li>Double-click the file to open it in the allocation viewer.
248   <p>The allocation viewer allows you to view and analyze the allocations your app made while
249   running. </p> </li>
250</ol>
251
252
253<h3>Data file access</h3>
254<p>The Android SDK tools, such as <a href="{@docRoot}tools/help/systrace.html">Systrace</a>,
255<a href="{@docRoot}tools/help/logcat.html">logcat</a>, and
256<a href="{@docRoot}tools/help/traceview.html">Traceview</a>, generate performance and debugging
257data for detailed app analysis.</p>
258
259<p>To view the available generated data files, click <strong>Captures</strong> in the left
260corner of the runtime window. In the list of the generated files, double-click a file to view
261the data. Right-click any <code>.hprof</code> files to convert them to a standard
262<a href="{@docRoot}tools/help/hprof-conv.html"><code>.hprof</code> </a> file format.</p>
263
264
265<h3>Code inspections</h3>
266<p>In Android Studio, the configured <a href="{@docRoot}tools/help/lint.html"><code>lint</code></a>
267and other IDE inspections run automatically whenever you compile your program. In addition to the
268configured {@code lint} checks, additional
269<a class="external-link" href="https://www.jetbrains.com/idea/help/inspection-basics.html?search=inspection"
270target="_blank">IntelliJ code inspections</a> and annotation validation run to streamline code
271review.</p>
272
273
274<p>Android Studio enables several <code>lint</code> checks
275to ensure:
276<ul>
277  <li><code> Cipher.getInstance()</code> is used with safe values</li>
278  <li>In custom Views, the associated declare-styleable for the custom view uses the same
279  base name as the class name</li>
280  <li>Security check for fragment injection</li>
281  <li>Where ever property assignment no longer works as expected</li>
282  <li>Gradle plugin version is compatible with the SDK</li>
283  <li>Right to left validation </li>
284  <li>Required API version</li>
285  <li>many others</li>
286</ul>
287
288
289<p>Hovering over an inspection error displays the full issue explanation inline for easy error
290resolution. There is also a helpful hyperlink at the end of the error message for additional
291error information.</p>
292
293<p>With Android Studio, you can also run {@code lint} inspections for a specific build variant, or
294for all build variants. You can configure the {@code lint} inspections that run by adding a
295<code>lintOptions</code> property to the Android settings in the <code>build.gradle</code>
296file.  </p>
297
298<pre>
299android {
300    lintOptions {
301       // set to true to turn off analysis progress reporting by lint
302       quiet true
303       // if true, stop the gradle build if errors are found
304       abortOnError false
305       // if true, only report errors
306       ignoreWarnings true
307    }
308</pre>
309
310
311<p>You can also manage inspection profiles and configure inspections within Android Studio.
312Choose <strong>File &gt; Settings &gt;</strong>, expand the <strong>Editor</strong> options,
313and select <strong>Inspections</strong>.
314The <em>Inspection Configuration</em> page appears with the supported inspections.</p>
315<p><img src="{@docRoot}images/tools/studio-inspections-config.png" alt="" /> </p>
316<p class="img-caption"><strong>Figure 5.</strong> Configure inspections.</p>
317
318<p class="note"><strong>Note:</strong> To change the behavior of specific
319inspection notifications, change the inspection severity, for example from <em>warning</em>
320to <em>error</em>. </p>
321
322
323<p>To manually run inspections in Android Studio, choose <strong>Analyze &gt; Inspect Code</strong>.
324The <em>Inspections Scope</em> dialog appears so you can specify the desired inspection profile and scope.</p>
325
326
327
328<h4>Running inspections from the command line</h4>
329<p>You can also run {@code lint} inspections from the command line in your SDK directory. </p>
330<pre>
331sdk$ lint [flags] <project directories>
332</pre>
333
334<p class="note"><strong>Note:</strong> The {@code lint} <strong>--show</strong> and <strong>--list</strong>
335flags can be used to display the available issues and explanations. </p>
336
337
338<p>For more information, see
339<a href="{@docRoot}tools/debugging/improving-w-lint.html">Improving Your Code with {@code lint}</a>
340and <a href="{@docRoot}tools/help/lint.html">lint tool</a>.</p>
341
342
343
344<h3 id="annotations">Annotations in Android Studio</h3>
345<p>Android Studio supports annotations for variables, parameters, and return values to help you
346catch bugs, such as null pointer exceptions and resource type conflicts. The
347<a href="{@docRoot}tools/help/sdk-manager.html">Android SDK Manager</a> packages
348the {@link android.support.annotation Support-Annotations} library
349in the Android Support Repository for use with Android
350Studio. Android Studio validates the configured annotations during code inspection. </p>
351
352<p>To add annotations to your code in Android Studio, first add a dependency for the
353{@link android.support.annotation Support-Annotations} library:</p>
354<ol>
355 <li>Select <strong>File &gt; Project Structure</strong>.</li>
356 <li>In the <em>Project Structure</em> dialog, select the desired module, click the
357 <strong>Dependencies</strong> tab. </li>
358 <li>Click the <img src="{@docRoot}images/tools/studio-add-icon.png"/> icon to include a
359 <strong>Library dependency</strong>.</li>
360 <li>In the <em>Choose Library Dependency</em> dialog, select <code>support-annotations</code> and
361 click <strong>Ok</strong>. </li>
362</ol>
363
364<p>The <code>build.gradle</code> file is updated with the <code>support-annotations</code>
365dependency.</p>
366
367<p>You can also manually add this dependency to your <code>build.gradle</code> file, as shown in
368the following example.  </p>
369
370<pre>
371dependencies {
372    compile fileTree(dir: 'libs', include: ['*.jar'])
373    compile 'com.android.support:appcompat-v7:22.0.0'
374    <strong>compile 'com.android.support:support-annotations:22.0.0'</strong>
375}
376</pre>
377
378
379
380<h4>Inferring nullability</h4>
381<p>A nullability analysis scans the contracts throughout the method hierarchies in your code to
382detect:</p>
383<ul>
384 <li>Calling methods that can return null </li>
385 <li>Methods that should not return null </li>
386 <li>Variables, such as fields, local variables, and parameters, that can be null </li>
387 <li>Variables, such as fields, local variables, and parameters, that cannot hold a null value </li>
388</ul>
389
390<p>The analysis then automatically inserts the appropriate null annotations in the detected
391locations. </p>
392
393<p>To run a nullability analysis in Android Studio,
394select the <strong>Analyze &gt; Infer Nullity</strong>
395menu option. Android Studio inserts the Android
396{@link android.support.annotation.Nullable @Nullable} and
397{@link android.support.annotation.NonNull @NonNull} annotations in detected locations
398in your code. After running a null analysis, it's good practice to verify the injected
399annotations.</p>
400
401<p class="note"><strong>Note:</strong> The nullability analysis may insert the IntelliJ
402<a class="external-link" href="https://www.jetbrains.com/idea/help/-nullable-and-notnull-annotations.html?search=annotations">
403<code>&#64;Nullable</code></a> and
404<a class="external-link" href="https://www.jetbrains.com/idea/help/-nullable-and-notnull-annotations.html?search=annotations">
405<code>&#64;NotNull</code></a> annotations instead of the Android null annotations. When running
406a null analysis, manually search and replace any IntelliJ annotations or include
407<code>com.intellij:annotations:12.0</code> as a compile dependency in your
408<code>build.gradle</code> file. This example includes the IntelliJ annotations 12.0 library as a
409dependency in the <code>build.gradle</code> file:
410
411<pre>
412dependencies {
413    compile fileTree(dir: 'libs', include: ['*.jar'])
414    compile 'com.android.support:appcompat-v7:22.0.0'
415    compile 'com.android.support:support-annotations:22.0.0'
416    <strong>compile 'com.intellij:annotations:12.0'</strong>
417}
418</pre>
419
420</p>
421
422
423<h4>Validating annotations</h4>
424<p>You can also manually add nullability, resource, and enumerated annotations throughout your code
425to perform validations for a variety of reference values, such as
426<a href="{@docRoot}reference/android/R.string.html"><code>R.string</code></a> resources,
427<a href="{@docRoot}guide/topics/resources/drawable-resource.htm"><code>Drawable</code></a>
428resources,
429<a href="{@docRoot}reference/android/graphics/Color.html"><code>Color</code></a> resources,
430and enumerated constants. </p>
431
432<p>Run <strong>Analyze &gt; Inspect Code</strong> to validate the configured annotations. </p>
433
434<p>For a complete list of the supported annotations, either use the auto-complete feature to display
435the available options for the <code>import android.support.annotation.</code> statement or
436view the contents of the
437{@link android.support.annotation Support-Annotations}
438library. </p>
439
440<p>For more details about Android annotations, see
441<a href="{@docRoot}tools/debugging/annotations.html">Improving Code Inspection with Annotations</a>.
442
443
444
445<h3>Dynamic layout preview</h3>
446<p>Android Studio allows you to work with layouts in both a <em>Design View</em> </p>
447<p><img src="{@docRoot}images/tools/studio-helloworld-design.png" alt="" />
448</p>
449    <p class="img-caption"><strong>Figure 6.</strong> Hello World App with Design View.</p>
450
451<p>and a <em>Text View</em>. </p>
452
453    <p><img src="{@docRoot}images/tools/studio-helloworld-text.png" alt="" />
454    <pclass="img-caption"><strong>Figure 7.</strong> Hello World App with text view.</p>
455
456<p>Easily select and preview layout changes for different device images, display
457densities, UI modes, locales, and Android versions (multi-API version rendering).
458    <p><img src="{@docRoot}images/tools/studio-api-version-rendering.png" /></p>
459    <p class="img-caption"><strong>Figure 8.</strong> Multi-API version rendering.</p>
460
461
462<p>From the Design View, you can drag and drop elements from the Palette to the Preview or
463Component Tree. The Text View allows you to directly edit the XML settings, while previewing
464the device display. </p>
465
466
467<h3>Log messages</h3>
468<p>When you build and run your app with Android Studio, you can view adb and device log messages
469(logcat) by clicking <strong>Android</strong> at the bottom of the window.</p>
470
471<p>If you want to debug your app with the
472<a href="{@docRoot}tools/help/monitor.html">Android Debug Monitor</a>, you can launch it by
473clicking <strong>Monitor</strong>
474<img src="{@docRoot}images/tools/monitor-studio.png" style="vertical-align:bottom;margin:0;height:19px"/>
475in the toolbar. The Debug Monitor is where you can find the complete set of
476<a href="{@docRoot}tools/debugging/ddms.html">DDMS</a> tools for profiling your app,
477controlling device behaviors, and more. It also includes the Hierarchy Viewer tools to help
478<a href="{@docRoot}tools/debugging/debugging-ui.html"> optimize your layouts</a>.</p>
479
480
481
482
483
484