First, explore Android Studio

Source: Internet
Author: User
Tags closing tag version control system maven central android sdk manager

Explore the Android studio content in this article
    1. Project structure
    2. Interface
    3. Gradle Build System
    4. Debugging and analysis tools

Android Studio is the official Android app development integrated development Environment (IDE) based on IntelliJ idea. In addition to IntelliJ's powerful code editor and developer tools, Android Studio offers more features that improve the efficiency of Android app building, such as:

    • A flexible building system based on Gradle
    • Fast and feature-rich simulator
    • A unified environment that can be developed for all Android devices
    • Instant run to push changes to a running app without building a new APK
    • Code templates and GitHub integrations to help you build common app features and import sample code
    • Extensive testing tools and frameworks
    • Lint tools to capture performance, ease of use, version compatibility, and other issues
    • C + + and NDK support
    • Built-in support for Google Cloud platform to easily integrate Google Cloud Messaging and App engine

This page describes the basic features of Android Studio. For a summary of the latest changes, see the Android Studio release notes.

Project structure

Figure 1. The project file in Android view.

Each project in Android Studio contains one or more modules that contain source code files and resource files. Module types include:

    • Android Application Module
    • Library Module
    • Google APP engine Module

By default, Android Studio displays your project files in the Android Project view, as shown in 1. The view is organized by module, which allows you to quickly access key source files for your project.

All build files are displayed at the top level of the project hierarchy Gradle Scripts , and each application module contains the following folders:

    • manifests: contains AndroidManifest.xml files.
    • java: Contains Java source code files, including JUnit test code.
    • res: Contains all non-code resources, such as XML layouts, UI strings, and bitmap images.

The ANDROID project structure on disk differs from this flat project structure. To see the actual project file structure, select Projectfrom the project drop-down menu (shown in Figure 1 as Android).

You can also customize the view of the project file, highlighting specific aspects of app development: for example, selecting the problems view of a project displays a link to a source file that contains any identified encoding and grammatical errors, such as a missing XML element closing tag in the layout file.

Figure 2. A project file in the problems view that displays the layout file that has the problem.

For more information, see Managing your project.

Interface

The main windows of the Android Studio are made up of several logical regions that are labeled in Figure 3.

Figure 3. Android Studio main window.

    1. the toolbar provides tools to perform various actions, including running apps and launching Android tools.
    2. The navigation bar helps you navigate through the project and open the file for editing. This area provides a streamlined view of the structure shown in the Project window.
    3. The Editor window is the area where you create and modify code. The editor may vary depending on the current file type. For example, when you view a layout file, the editor displays the layout editor.
    4. The tool window bar runs outside the IDE window and contains buttons that you can use to expand or collapse individual tool windows.
    5. tool windows provide access to specific tasks, such as project management, search, and versioning. You can expand and collapse these windows.
    6. The status bar displays the status of the project and the IDE itself, as well as any warnings or messages.

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

At any time, you can search for source code, databases, actions, and user interface elements by pressing the Shift key twice or tapping the magnifying glass in the upper right corner of the Android Studio window. This feature is useful, for example, when you forget how to trigger a specific IDE operation, you can use this feature to find it.

tool window

Instead of using a preset window, Android Studio automatically displays relevant tool windows as you work, depending on the context. By default, the most commonly used tool window is pinned to the tool window bar at the edge of the app window.

    • To expand or collapse a tool window, click the tool's name in the tool window bar. You can also drag, pin, Unpin, associate, and Detach tool windows.
    • To return to the current Default tool window layout, click Window > Restore default layout or click window > Store now layout as default custom Default layout is defined.
    • To show or hide the entire tool window bar, click the window icon in the lower-left corner of the Android Studio window.
    • To find a specific tool window, hover the mouse pointer over the window icon and select the appropriate tool window from the menu.

You can also use keyboard shortcuts to open tool windows. Table 1 lists the shortcut keys for the most commonly used windows.

table 1. Keyboard shortcuts for some utility windows.

tool windows Windows and Linux Mac
Project alt+1 command+1
Version Control alt+9 command+9
Run shift+f10 control+r
Debug shift+f9 control+d
Android Monitor alt+6 command+6
Return to Editor ESC ESC
Hide all Tool Windows control+shift+f12 command+shift+f12

If you want to hide all toolbars, tool windows, and Editor tabs, click View > Enter distraction free Mode. This action enables interference-free mode . To exit "No interference mode", click View > Exit distractionfree.

You can use Quick Search to perform searches and filters in most tool windows in Android Studio. To use Quick Search, select the tool window and type your search query.

For more tips, see keyboard shortcuts.

Automatic code completion

Android Studio has three types of code autocomplete that you can access using keyboard shortcuts.

table 2. Keyboard shortcuts for automatic code completion.

type Description Windows and Linux Mac
Basic Auto-Complete Displays basic recommendations for variables, types, methods, and expressions. If you call basic AutoComplete twice in a row, more results are displayed, including private and non-imported static members. control+ spaces control+ spaces
Intelligent Auto-Complete Displays the relevant options depending on the context. Intelligent AutoComplete identifies expected types and data streams. If you call Smart AutoComplete twice in a row, more results are displayed, including the chain. control+shift+ spaces control+shift+ spaces
Statement Auto-Complete Automatically completes the current statement for you, adding missing parentheses, braces, curly braces, and formatting. Control+shift+enter Shift+command+enter

You can also press Alt+enter to perform a quick fix and display the recommended action. For more information about code completion, see Code AutoComplete.

Find Sample Code

The code sample browser in Android Studio can help you find high-quality Android code samples from Google based on the symbols currently highlighted in your project. For more information, see Find sample code.

Navigation

Here are some tips for manipulating Android Studio.

    • Use the recent file operation to switch between recently accessed files. Press control+e(on Mac, press command+e) to bring up the recent files action. The last file accessed is selected by default. In this operation, you can also access any tool window through the left column.
    • Use the file structure operation to view the structure of the current file. Press control+f12(on Mac, press COMMAND+F12) to bring up the file structure action. You can use this action to quickly navigate to any part of the current file.
    • Use the navigate to class action to search for and navigate to a specific class in your project. Press control+n(on Mac, press Command+o) to bring up this action. Navigate to class supports complex expressions, including hump, path, line navigation, and middle name matching. If this operation is called two times in a row, results outside the project class are displayed.
    • Navigate to a file or folder using the navigate to file operation. Press control+shift+n(on Mac, press Command+shift+o) to bring up the navigate to file action. To search for a folder without searching for a file, add "/" at the end of the expression.
    • Navigate to a method or field by name using the navigate to symbol action. Press control+shift+alt+n(on Mac, press Command+shift+alt+o) to bring up the navigate to symbol action.
    • Press Alt+f7 to find all code snippets that refer to the class, method, field, parameter, or statement at the current cursor position.

Styling and formatting

When you edit, Android Studio automatically applies the formatting and styling specified in the Code style settings. You can customize code style settings in a programming language, including conventions that specify tabs and indents, spaces, line breaks, curly braces, and blank lines. To customize your code style settings, click File > Settings > Editor > Code style(on Mac, click Android Studio > Preferences > Editor > Code Style).

Although the IDE automatically applies formatting when you work, you can also explicitly call reformat code actions by pressing control+alt+l(on Mac, pressing opt+command+l), or by pressing Control+alt+i(on Mac, press alt+option+i*) to automatically indent all lines.

Figure 5. The code before formatting.

Figure 6. The code after formatting.

Version Control basics

Android Studio supports multiple version control systems (VCS), including Git, GitHub, CVS, Mercurial, Subversion, and Google Cloud Source repositories.

After importing your app into Android studio, use the Android studio VCS menu option to enable VCS support for the required version control system, create repositories, import new files to version control, and perform other versioning operations:

    1. In the Android Studio VCS menu, click Enable Version Control integration.
    2. Select the version control system that you want to associate with the project root from the drop-down menu, and then click OK.

At this point, the VCS menu displays multiple versioning options based on the system you select.

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

Gradle Build System

Android Studio builds systems based on Gradle and offers more Android-oriented features through the Android plugin for Gradle. The build system can be run as an integration tool from the Android Studio menu or independently from the command line. You can take advantage of the capabilities of the build system to do the following:

    • Customize, configure, and extend the build process.
    • Create multiple APK with different features for your app using the same projects and modules.
    • Reuse code and resources between different source code sets.

With Gradle flexibility, you can achieve all of these purposes without modifying the application core source files. Android Studio builds the file to build.gradle name it. These files are plain text files and are built using the elements provided by the Android plugin for Gradle in Groovy syntax configuration. Each project has a top-level build file for the entire project and a separate module-level build file for each module. When you import an existing project, Android Studio automatically generates the necessary build files.

For more information about building your system and how to configure it, see Configuring builds.

Build variants

The build system helps you create different versions of the same app from one project. You can use this feature if you have both a free version and a paid version of the app, or if you want to distribute multiple APK for different device configurations on Google Play.

For more information about configuring build variants, see Configuring Gradle builds.

APK Split

With APK split, you can efficiently create multiple apk based on screen density or ABI. For example, you can use the APK splitter to create separate hdpi and MDPI versions of your app, still treat them as a variant, and allow them to share test apps, Javac, DX, and Proguard settings.

For more information about using the APK split, see APK split.

Resource compression

The resource compression feature in Android Studio automatically removes unused resources from your packaged app and library dependencies. For example, if your app is using the Google Play service to access Google Drive features, and you're not currently using Google Sign-in, the resource compression feature can delete SignInButton various drawing assets of the button.

Note: resource compression works in conjunction with the Code compression tool (for example, Proguard).

For more information about compressing code and resources, see compressing code and resources.

Managing Dependencies

The dependencies of the project are build.gradle specified by name in the file. Gradle can automatically find your dependencies and provide them in the build. You can build.gradle declare module dependencies, remote binary dependencies, and local binary dependencies in a file. The Maven central repository is used by default for Android Studio configuration items. (This configuration is included in the project's top-level build file.) For more information about configuring dependencies, see Configuring Build variants.

Debugging and analysis tools

Android Studio can help you debug and improve the performance of your code, including inline debugging and performance analysis tools.

inline debugging

Use inline debugging to inline validate references, expressions, and variable values in the debugger view to improve code-checking efficiency. Inline debugging information includes:

    • Inline Variable Value
    • Reference object referencing a selected object
    • Method return value
    • Lambda and operator expressions
    • Tool tip values

Figure 7. The value of the inline variable.

To enable inline debugging, in the Debug window, click Settings , and then select the Show Values Inline check box.

Performance Monitor

Android Studio provides performance monitors that make it easier for you to track your app's memory and CPU usage, find objects that have been deallocated, find memory leaks, and optimize graphics performance and analyze network requests. When running your app on a device or emulator, open the Android Monitor Tool window and click on the Monitors tab.

For more information about Performance Monitor, see Android Monitor.

Heap Dumps

When you monitor memory usage in Android Studio, you can start garbage collection at the same time and dump the Java heap into a heap snapshot file in the Android proprietary HPROF binary format. The HPROF Viewer displays classes, instances of each class, and reference trees to help you track memory usage and find memory leaks.

For more information about using the heap dump feature, see Dump and analyze the Java heap.

Assigning trackers

Android Studio allows you to track memory allocations while monitoring memory usage. The Trace memory allocation feature allows you to monitor where objects are assigned when performing certain operations. Once you understand these allocations, you can adjust the method calls associated with these operations accordingly to optimize your application's performance and memory usage.

For more information about tracking and analyzing assignments, see assigning trackers.

Data file access

Android SDK tools such as Systrace, Logcat, and Traceview generate performance and debug data for detailed analysis of your application.

To view the data files that have been generated, open the Captures tool window. In the list of generated files, double-click the appropriate file to view the data. Right-click any .hprof file to convert it to a standard .hprof file format.

Code Check

Every time you compile your program, Android Studio will automatically run the configured Lint and other IDE checks to help you easily identify and correct code structure quality issues.

The Lint tool checks to see if your Android project source files have potential errors, and whether optimization improvements are needed in terms of correctness, security, performance, availability, accessibility, and internationalization.

Figure 8. Results of Lint Check in Android Studio.

In addition to the Lint check, Android Studio can also perform IntelliJ code checking and annotation validation to streamline your coding workflow.

For more information, see Using Lint to improve your code and Lint tools.

Annotations in Android Studio

Android Studio supports adding annotations to variables, parameters, and return values to help you catch errors, such as null pointer exceptions and resource type conflicts. The Android SDK Manager incorporates the support note library into the Android support repository for use with Android Studio. Android Studio validates the configured annotations during code review.

For more details on Android annotations, see Improving code checking with annotations.

Log Messages

When you build and run your app using Android Studio, you can view ADB output and device log messages (Logcat) by tapping Android Monitor at the bottom of the window.

If you want to use the Android device Monitor to debug your app, you can click Tools > Android > Android device Monitor to start the unit monitors. The full set of DDMS tools is available in Device monitor, which you can use to perform operations such as application analysis and device behavior control. In addition, the monitor includes a Hierarchy Viewer tool to help you optimize your layout.

First, explore Android Studio

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.