Meet Android Studio

Android Studio is the official Integrated Development Environment (IDE) for
Android app development, based on
IntelliJ IDEA
. On top of IntelliJ's powerful code editor and developer tools, Android
Studio offers even more features that enhance your productivity when building
Android apps, such as:

A flexible Gradle-based build system

A fast and feature-rich emulator

A unified environment where you can develop for all Android devices

Instant Run to push changes to your running app without building a new APK

Code templates and GitHub integration to help you build common app features
and import sample code

Extensive testing tools and frameworks

Lint tools to catch performance, usability, version compatibility, and other
problems

C++ and NDK support

Built-in support for
Google Cloud Platform,
making it easy to integrate Google Cloud Messaging and App Engine

The Android project structure on disk differs from this flattened
representation. To see the actual file structure of the project, select
Project from the Project dropdown (in figure 1, it's showing as
Android).

You can also customize the view of the project files to focus on specific
aspects of your app development. For example, selecting the Problems view of
your project displays links to the source files containing any recognized
coding and syntax errors, such as a missing XML element closing tag in a layout
file.

Figure 2. The project files in Problems
view, showing a layout file with a problem.

The user interface

The Android Studio main window is made up of several logical areas identified in
figure 3.

Figure 3. The Android Studio main window.

The toolbar lets you carry out a wide range of actions, including
running your app and launching Android tools.

The navigation bar helps you navigate through your project and open
files for editing. It provides a more compact view of the structure visible in
the Project window.

The editor window is where you create and modify code. Depending on
the current file type, the editor can change. For example, when viewing a
layout file, the editor displays the Layout Editor.

The tool window bar runs around the outside of the IDE window and
contains the buttons that allow you to expand or collapse individual tool
windows.

The tool windows give you access to specific tasks like project management,
search, version control, and more. You can expand them and collapse them.

The status bar displays the status of your project and the IDE itself,
as well as any warnings or messages.

You can organize the main window to give yourself more screen space by hiding
or moving toolbars and tool windows. You can also use keyboard shortcuts to
access most IDE features.

At any time, you can search across your source code, databases, actions,
elements of the user interface, and so on, by double-pressing the Shift key, or
clicking the magnifying glass in the upper right-hand corner of the Android
Studio window. This can be very useful if, for example, you are trying to
locate a particular IDE action that you have forgotten how to trigger.

Tool windows

Instead of using preset perspectives, Android Studio follows your context and
automatically brings up relevant tool windows as you work. By default, the most
commonly used tool windows are pinned to the tool window bar at the edges of
the application window.

To expand or collapse a tool window, click the tool’s name in the tool
window bar. You can also drag, pin, unpin, attach, and detach tool windows.

Code completion

Android Studio has three types of code completion, which you can access using
keyboard shortcuts.

Table 2. Keyboard shortcuts for code completion.

Type

Description

Windows and Linux

Mac

Basic Completion

Displays basic suggestions for variables, types, methods, expressions,
and so on. If you call basic completion twice in a row, you see more
results, including private members and non-imported static members.

Control+Space

Control+Space

Smart Completion

Displays relevant options based on the context. Smart completion is
aware of the expected type and data flows. If you call Smart Completion
twice in a row, you see more results, including chains.

Find sample code

The Code Sample Browser in Android Studio helps you find high-quality,
Google-provided Android code samples based on the currently highlighted symbol
in your project. For more information, see
Find sample code.

Navigation

Here are some tips to help you move around Android Studio.

Switch between your recently accessed files using the Recent Files
action. Press Control+E (Command+E on a Mac) to bring up the Recent
Files action. By default, the last accessed file is selected. You can also
access any tool window through the left column in this action.

View the structure of the current file using the File Structure action.
Bring up the File Structure action by pressing Control+F12
(Command+F12 on a Mac). Using this action, you can quickly navigate to any
part of your current file.

Search for and navigate to a specific class in your project using the
Navigate to Class action. Bring up the action by pressing Control+N
(Command+O on a Mac). Navigate to Class supports sophisticated
expressions, including camel humps, paths, line navigate to, middle name
matching, and many more. If you call it twice in a row, it shows you the
results out of the project
classes.

Navigate to a file or folder using the Navigate to File action. Bring up
the Navigate to File action by pressing Control+Shift+N
(Command+Shift+O on a Mac). To search for folders rather than files, add a
/ at the end of your expression.

Navigate to a method or field by name using the Navigate to Symbol action.
Bring up the Navigate to Symbol action by pressing Control+Shift+Alt+N
(Command+Option+O on a Mac).

Find all the pieces of code referencing the class, method, field, parameter,
or statement at the current cursor position by pressing Alt+F7 (Option+F7 on a Mac).

Although the IDE automatically applies formatting as you work, you can also
explicitly call the Reformat Code action by pressing Control+Alt+L
(Opt+Command+L on a Mac), or auto-indent all lines by pressing
Control+Alt+I (Control+Option+I on a Mac).

Figure 4. Code before formatting.

Figure 5. Code after formatting.

Version control basics

After importing your app into Android Studio, use the Android Studio VCS 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:

From the Android Studio VCS menu, click Enable Version Control
Integration.

From the drop-down menu, select a version control system to associate with
the project root, and then click OK.

The VCS menu now displays a number of version control options based on the
system you selected.

Note: You can also use the File >
Settings > Version Control menu option to set up and modify the version
control settings.

Gradle build system

Android Studio uses Gradle as the foundation of the build system, with more
Android-specific capabilities provided by the
Android plugin for Gradle. This build
system runs 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 do the following:

Customize, configure, and extend the build process.

Create multiple APKs for your app, with different features using the same
project and modules.

Reuse code and resources across sourcesets.

By employing the flexibility of Gradle, you can achieve all of this without
modifying your app's core source files. Android Studio build files are named
build.gradle. They are plain text files that use Groovy syntax to configure the build with
elements provided by the Android plugin for Gradle. Each project has one
top-level build file for the entire project and separate module-level build
files for each module. When you import an existing project, Android Studio
automatically generates the necessary build files.

Build variants

The build system can help you create different versions of the same application
from a single project. This is useful when you have both a free version and a
paid version of your app, or if you want to distribute multiple APKs for
different device configurations on Google Play.

Multiple APK support

Multiple APK support allows you to efficiently create multiple APKs based on screen density or
ABI. For example, you can create separate APKs of an app for the hdpi and mdpi screen densities,
while still considering them a single variant and allowing them to
share test APK, javac, dx, and ProGuard settings.

Resource shrinking

Resource shrinking in Android Studio automatically removes unused resources
from your packaged app and library dependencies. For example, if your
application is using Google Play services
to access Google Drive functionality, and you are not currently using
Google Sign-In, then resource shrinking can
remove the various drawable assets for theSignInButton buttons.

Note: Resource shrinking works in conjunction
with code shrinking tools, such as ProGuard.

Managing dependencies

Dependencies for your project are specified by name in the build.gradle file.
Gradle takes care of finding your dependencies and making them available in your
build. You can declare module dependencies, remote binary dependencies, and
local binary dependencies in your build.gradle file. Android Studio configures
projects to use the Maven Central Repository by default. (This configuration is
included in the top-level build file for the project.) For more information
about configuring dependencies, read
Add build dependencies.

Debug and profile tools

Android Studio assists you in debugging and improving the performance of your
code, including inline debugging and performance analysis tools.

Heap dump

When you’re profiling memory usage in Android Studio, you can simultaneously
initiate garbage collection and dump the Java heap to a heap snapshot in an
Android-specific HPROF binary format file. The HPROF viewer displays classes,
instances of each class, and a reference tree to help you track memory usage
and find memory leaks.

Memory Profiler

You can use Memory Profiler to track memory allocation and watch where objects
are being allocated when you perform certain actions. Knowing these allocations
enables you to optimize your app’s performance and memory use by adjusting the
method calls related to those actions.

Data file access

The Android SDK tools, such as Systrace,
and logcat,
generate performance and debugging data for detailed app analysis.

To view the available generated data files, open the Captures tool window. In
the list of the generated files, double-click a file to view the data.
Right-click any .hprof files to convert them to the standard
Investigate your RAM usage file format.

Code inspections

Whenever you compile your program, Android Studio automatically runs configured
Lint and other
IDE inspections to help you easily
identify and correct problems with the structural quality of your code.

Annotations in Android Studio

Android Studio supports annotations for variables, parameters, and return
values to help you catch bugs, such as null pointer exceptions and resource
type conflicts. The Android SDK Manager packages the Support-Annotations
library in the Android Support Repository for use with Android Studio. Android
Studio validates the configured annotations during code inspection.